@kreuzberg/node 4.9.9 → 4.10.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/README.md +25 -21
- package/dist/cli.js +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/cli.mjs.map +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/errors.mjs.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/types.js.map +1 -1
- package/index.js +52 -52
- package/metadata.d.ts +292 -292
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
<a href="https://central.sonatype.com/artifact/dev.kreuzberg/kreuzberg">
|
|
22
22
|
<img src="https://img.shields.io/maven-central/v/dev.kreuzberg/kreuzberg?label=Java&color=007ec6" alt="Java">
|
|
23
23
|
</a>
|
|
24
|
-
<a href="https://github.com/kreuzberg-dev/kreuzberg/releases">
|
|
25
|
-
<img src="https://img.shields.io/github/v/tag/kreuzberg-dev/kreuzberg?label=Go&color=007ec6&filter=v4
|
|
24
|
+
<a href="https://github.com/kreuzberg-dev/kreuzberg-lts/releases">
|
|
25
|
+
<img src="https://img.shields.io/github/v/tag/kreuzberg-dev/kreuzberg-lts?label=Go&color=007ec6&filter=v4.*" alt="Go">
|
|
26
26
|
</a>
|
|
27
27
|
<a href="https://www.nuget.org/packages/Kreuzberg/">
|
|
28
28
|
<img src="https://img.shields.io/nuget/v/Kreuzberg?label=C%23&color=007ec6" alt="C#">
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
<a href="https://kreuzberg-dev.r-universe.dev/kreuzberg">
|
|
37
37
|
<img src="https://img.shields.io/badge/R-kreuzberg-007ec6" alt="R">
|
|
38
38
|
</a>
|
|
39
|
-
<a href="https://github.com/kreuzberg-dev/kreuzberg/pkgs/container/kreuzberg">
|
|
39
|
+
<a href="https://github.com/kreuzberg-dev/kreuzberg-lts/pkgs/container/kreuzberg">
|
|
40
40
|
<img src="https://img.shields.io/badge/Docker-007ec6?logo=docker&logoColor=white" alt="Docker">
|
|
41
41
|
</a>
|
|
42
42
|
<a href="https://artifacthub.io/packages/search?repo=kreuzberg">
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
</a>
|
|
45
45
|
|
|
46
46
|
<!-- Project Info -->
|
|
47
|
-
<a href="https://github.com/kreuzberg-dev/kreuzberg/blob/main/LICENSE">
|
|
47
|
+
<a href="https://github.com/kreuzberg-dev/kreuzberg-lts/blob/main/LICENSE">
|
|
48
48
|
<img src="https://img.shields.io/badge/License-MIT-007ec6" alt="License">
|
|
49
49
|
</a>
|
|
50
50
|
<a href="https://docs.kreuzberg.dev">
|
|
@@ -58,7 +58,11 @@
|
|
|
58
58
|
</a>
|
|
59
59
|
</div>
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
> [!NOTE]
|
|
62
|
+
> **Kreuzberg v4 LTS** — the long-term-support line for Kreuzberg **v4**. Active development has moved to
|
|
63
|
+
> **[Xberg](https://github.com/xberg-io/xberg)** (v5+), which receives all new features. This line receives
|
|
64
|
+
> critical bug and security fixes until the **end of 2026, on a best-effort basis**.
|
|
65
|
+
> See the **[migration guide & LTS policy →](https://docs.kreuzberg.dev/lts/)**
|
|
62
66
|
|
|
63
67
|
<div align="center" style="margin-top: 20px;">
|
|
64
68
|
<a href="https://discord.gg/xt9WY3GnKR">
|
|
@@ -295,10 +299,10 @@ try {
|
|
|
295
299
|
|
|
296
300
|
### Next Steps
|
|
297
301
|
|
|
298
|
-
- **[Installation Guide](https://kreuzberg.dev/getting-started/installation/)** - Platform-specific setup
|
|
299
|
-
- **[API Documentation](https://kreuzberg.dev/api/)** - Complete API reference
|
|
300
|
-
- **[Examples & Guides](https://kreuzberg.dev/guides/)** - Full code examples and usage guides
|
|
301
|
-
- **[Configuration Guide](https://kreuzberg.dev/guides/configuration/)** - Advanced configuration options
|
|
302
|
+
- **[Installation Guide](https://docs.kreuzberg.dev/getting-started/installation/)** - Platform-specific setup
|
|
303
|
+
- **[API Documentation](https://docs.kreuzberg.dev/api/)** - Complete API reference
|
|
304
|
+
- **[Examples & Guides](https://docs.kreuzberg.dev/guides/)** - Full code examples and usage guides
|
|
305
|
+
- **[Configuration Guide](https://docs.kreuzberg.dev/guides/configuration/)** - Advanced configuration options
|
|
302
306
|
|
|
303
307
|
|
|
304
308
|
|
|
@@ -389,9 +393,9 @@ This binding uses NAPI-RS to provide native Node.js bindings with:
|
|
|
389
393
|
| **Diagnostics** | Parse errors with line/column positions |
|
|
390
394
|
| **Syntax-Aware Chunking** | Split code by semantic boundaries, not arbitrary byte offsets |
|
|
391
395
|
|
|
392
|
-
Powered by [tree-sitter-language-pack](https://github.com/
|
|
396
|
+
Powered by [tree-sitter-language-pack](https://github.com/xberg-io/tree-sitter-language-pack) — [documentation](https://docs.tree-sitter-language-pack.xberg.io).
|
|
393
397
|
|
|
394
|
-
**[Complete Format Reference](https://kreuzberg.dev/reference/formats/)**
|
|
398
|
+
**[Complete Format Reference](https://docs.kreuzberg.dev/reference/formats/)**
|
|
395
399
|
|
|
396
400
|
### Key Capabilities
|
|
397
401
|
|
|
@@ -413,7 +417,7 @@ Powered by [tree-sitter-language-pack](https://github.com/kreuzberg-dev/tree-sit
|
|
|
413
417
|
- **Memory Efficient** - Stream large files without loading entirely into memory
|
|
414
418
|
- **Language Detection** - Detect and support multiple languages in documents
|
|
415
419
|
|
|
416
|
-
- **Code Intelligence** - Extract structure, imports, exports, symbols, and docstrings from [248 programming languages](https://docs.tree-sitter-language-pack.
|
|
420
|
+
- **Code Intelligence** - Extract structure, imports, exports, symbols, and docstrings from [248 programming languages](https://docs.tree-sitter-language-pack.xberg.io) via tree-sitter
|
|
417
421
|
|
|
418
422
|
- **Configuration** - Fine-grained control over extraction behavior
|
|
419
423
|
|
|
@@ -479,7 +483,7 @@ console.log(result.content);
|
|
|
479
483
|
|
|
480
484
|
Kreuzberg supports extensible post-processing plugins for custom text transformation and filtering.
|
|
481
485
|
|
|
482
|
-
For detailed plugin documentation, visit [Plugin System Guide](https://kreuzberg.dev/guides/plugins/).
|
|
486
|
+
For detailed plugin documentation, visit [Plugin System Guide](https://docs.kreuzberg.dev/guides/plugins/).
|
|
483
487
|
|
|
484
488
|
|
|
485
489
|
|
|
@@ -488,7 +492,7 @@ For detailed plugin documentation, visit [Plugin System Guide](https://kreuzberg
|
|
|
488
492
|
|
|
489
493
|
Generate vector embeddings for extracted text using the built-in ONNX Runtime support. Requires ONNX Runtime installation.
|
|
490
494
|
|
|
491
|
-
**[Embeddings Guide](https://kreuzberg.dev/features/#embeddings)**
|
|
495
|
+
**[Embeddings Guide](https://docs.kreuzberg.dev/features/#embeddings)**
|
|
492
496
|
|
|
493
497
|
|
|
494
498
|
|
|
@@ -514,17 +518,17 @@ results.forEach((result, i) => {
|
|
|
514
518
|
|
|
515
519
|
For advanced configuration options including language detection, table extraction, OCR settings, and more:
|
|
516
520
|
|
|
517
|
-
**[Configuration Guide](https://kreuzberg.dev/guides/configuration/)**
|
|
521
|
+
**[Configuration Guide](https://docs.kreuzberg.dev/guides/configuration/)**
|
|
518
522
|
|
|
519
523
|
## Documentation
|
|
520
524
|
|
|
521
|
-
- **[Official Documentation](https://kreuzberg.dev/)**
|
|
522
|
-
- **[API Reference](https://kreuzberg.dev/reference/api-typescript/)**
|
|
523
|
-
- **[Examples & Guides](https://kreuzberg.dev/guides/)**
|
|
525
|
+
- **[Official Documentation](https://docs.kreuzberg.dev/)**
|
|
526
|
+
- **[API Reference](https://docs.kreuzberg.dev/reference/api-typescript/)**
|
|
527
|
+
- **[Examples & Guides](https://docs.kreuzberg.dev/guides/)**
|
|
524
528
|
|
|
525
529
|
## Contributing
|
|
526
530
|
|
|
527
|
-
Contributions are welcome! See [Contributing Guide](https://github.com/kreuzberg-dev/kreuzberg/blob/main/CONTRIBUTING.md).
|
|
531
|
+
Contributions are welcome! See [Contributing Guide](https://github.com/kreuzberg-dev/kreuzberg-lts/blob/main/CONTRIBUTING.md).
|
|
528
532
|
|
|
529
533
|
## License
|
|
530
534
|
|
|
@@ -533,5 +537,5 @@ MIT License - see LICENSE file for details.
|
|
|
533
537
|
## Support
|
|
534
538
|
|
|
535
539
|
- **Discord Community**: [Join our Discord](https://discord.gg/xt9WY3GnKR)
|
|
536
|
-
- **GitHub Issues**: [Report bugs](https://github.com/kreuzberg-dev/kreuzberg/issues)
|
|
537
|
-
- **Discussions**: [Ask questions](https://github.com/kreuzberg-dev/kreuzberg/discussions)
|
|
540
|
+
- **GitHub Issues**: [Report bugs](https://github.com/kreuzberg-dev/kreuzberg-lts/issues)
|
|
541
|
+
- **Discussions**: [Ask questions](https://github.com/kreuzberg-dev/kreuzberg-lts/discussions)
|
package/dist/cli.js
CHANGED
|
@@ -66,7 +66,7 @@ function main(argv) {
|
|
|
66
66
|
}
|
|
67
67
|
if (!cliPath) {
|
|
68
68
|
console.error(
|
|
69
|
-
"The embedded Kreuzberg CLI binary could not be located. This indicates a packaging issue; please open an issue at https://github.com/kreuzberg-dev/kreuzberg/issues so we can investigate."
|
|
69
|
+
"The embedded Kreuzberg CLI binary could not be located. This indicates a packaging issue; please open an issue at https://github.com/kreuzberg-dev/kreuzberg-lts/issues so we can investigate."
|
|
70
70
|
);
|
|
71
71
|
return 1;
|
|
72
72
|
}
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../typescript/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n\n/**\n * Proxy entry point that forwards to the Rust-based Kreuzberg CLI.\n *\n * This keeps `npx kreuzberg` working without shipping an additional TypeScript CLI implementation.\n */\n\nimport { spawnSync } from \"node:child_process\";\nimport { existsSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport which from \"which\";\n\ndeclare global {\n
|
|
1
|
+
{"version":3,"sources":["../typescript/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n\n/**\n * Proxy entry point that forwards to the Rust-based Kreuzberg CLI.\n *\n * This keeps `npx kreuzberg` working without shipping an additional TypeScript CLI implementation.\n */\n\nimport { spawnSync } from \"node:child_process\";\nimport { existsSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport which from \"which\";\n\ndeclare global {\n var __filename: string | undefined;\n var __dirname: string | undefined;\n}\n\nfunction getDirectory(): string {\n if (typeof __filename !== \"undefined\") {\n return dirname(__filename);\n }\n try {\n const getUrl = new Function(\"return import.meta.url\");\n return dirname(fileURLToPath(getUrl()));\n } catch {\n return process.cwd();\n }\n}\n\nfunction main(argv: string[]): number {\n const args = argv.slice(2);\n\n let cliPath: string | undefined;\n try {\n cliPath = which.sync(\"kreuzberg-cli\");\n } catch {}\n\n if (!cliPath) {\n const __dirname = getDirectory();\n const devBinary = join(__dirname, \"..\", \"..\", \"..\", \"target\", \"release\", \"kreuzberg\");\n if (existsSync(devBinary)) {\n cliPath = devBinary;\n }\n }\n\n if (!cliPath) {\n console.error(\n \"The embedded Kreuzberg CLI binary could not be located. \" +\n \"This indicates a packaging issue; please open an issue at \" +\n \"https://github.com/kreuzberg-dev/kreuzberg-lts/issues so we can investigate.\",\n );\n return 1;\n }\n\n const result = spawnSync(cliPath, args, {\n stdio: \"inherit\",\n shell: false,\n });\n\n if (result.error) {\n console.error(`Failed to execute kreuzberg-cli: ${result.error.message}`);\n return 1;\n }\n\n return result.status ?? 1;\n}\n\nif (require.main === module) {\n process.exit(main(process.argv));\n}\n\nexport { main };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,gCAA0B;AAC1B,qBAA2B;AAC3B,uBAA8B;AAC9B,sBAA8B;AAC9B,mBAAkB;AAOlB,SAAS,eAAuB;AAC9B,MAAI,OAAO,eAAe,aAAa;AACrC,eAAO,0BAAQ,UAAU;AAAA,EAC3B;AACA,MAAI;AACF,UAAM,SAAS,IAAI,SAAS,wBAAwB;AACpD,eAAO,8BAAQ,+BAAc,OAAO,CAAC,CAAC;AAAA,EACxC,QAAQ;AACN,WAAO,QAAQ,IAAI;AAAA,EACrB;AACF;AAEA,SAAS,KAAK,MAAwB;AACpC,QAAM,OAAO,KAAK,MAAM,CAAC;AAEzB,MAAI;AACJ,MAAI;AACF,cAAU,aAAAA,QAAM,KAAK,eAAe;AAAA,EACtC,QAAQ;AAAA,EAAC;AAET,MAAI,CAAC,SAAS;AACZ,UAAM,YAAY,aAAa;AAC/B,UAAM,gBAAY,uBAAK,WAAW,MAAM,MAAM,MAAM,UAAU,WAAW,WAAW;AACpF,YAAI,2BAAW,SAAS,GAAG;AACzB,gBAAU;AAAA,IACZ;AAAA,EACF;AAEA,MAAI,CAAC,SAAS;AACZ,YAAQ;AAAA,MACN;AAAA,IAGF;AACA,WAAO;AAAA,EACT;AAEA,QAAM,aAAS,qCAAU,SAAS,MAAM;AAAA,IACtC,OAAO;AAAA,IACP,OAAO;AAAA,EACT,CAAC;AAED,MAAI,OAAO,OAAO;AAChB,YAAQ,MAAM,oCAAoC,OAAO,MAAM,OAAO,EAAE;AACxE,WAAO;AAAA,EACT;AAEA,SAAO,OAAO,UAAU;AAC1B;AAEA,IAAI,QAAQ,SAAS,QAAQ;AAC3B,UAAQ,KAAK,KAAK,QAAQ,IAAI,CAAC;AACjC;","names":["which"]}
|
package/dist/cli.mjs
CHANGED
|
@@ -39,7 +39,7 @@ function main(argv) {
|
|
|
39
39
|
}
|
|
40
40
|
if (!cliPath) {
|
|
41
41
|
console.error(
|
|
42
|
-
"The embedded Kreuzberg CLI binary could not be located. This indicates a packaging issue; please open an issue at https://github.com/kreuzberg-dev/kreuzberg/issues so we can investigate."
|
|
42
|
+
"The embedded Kreuzberg CLI binary could not be located. This indicates a packaging issue; please open an issue at https://github.com/kreuzberg-dev/kreuzberg-lts/issues so we can investigate."
|
|
43
43
|
);
|
|
44
44
|
return 1;
|
|
45
45
|
}
|
package/dist/cli.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../typescript/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n\n/**\n * Proxy entry point that forwards to the Rust-based Kreuzberg CLI.\n *\n * This keeps `npx kreuzberg` working without shipping an additional TypeScript CLI implementation.\n */\n\nimport { spawnSync } from \"node:child_process\";\nimport { existsSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport which from \"which\";\n\ndeclare global {\n
|
|
1
|
+
{"version":3,"sources":["../typescript/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n\n/**\n * Proxy entry point that forwards to the Rust-based Kreuzberg CLI.\n *\n * This keeps `npx kreuzberg` working without shipping an additional TypeScript CLI implementation.\n */\n\nimport { spawnSync } from \"node:child_process\";\nimport { existsSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport which from \"which\";\n\ndeclare global {\n var __filename: string | undefined;\n var __dirname: string | undefined;\n}\n\nfunction getDirectory(): string {\n if (typeof __filename !== \"undefined\") {\n return dirname(__filename);\n }\n try {\n const getUrl = new Function(\"return import.meta.url\");\n return dirname(fileURLToPath(getUrl()));\n } catch {\n return process.cwd();\n }\n}\n\nfunction main(argv: string[]): number {\n const args = argv.slice(2);\n\n let cliPath: string | undefined;\n try {\n cliPath = which.sync(\"kreuzberg-cli\");\n } catch {}\n\n if (!cliPath) {\n const __dirname = getDirectory();\n const devBinary = join(__dirname, \"..\", \"..\", \"..\", \"target\", \"release\", \"kreuzberg\");\n if (existsSync(devBinary)) {\n cliPath = devBinary;\n }\n }\n\n if (!cliPath) {\n console.error(\n \"The embedded Kreuzberg CLI binary could not be located. \" +\n \"This indicates a packaging issue; please open an issue at \" +\n \"https://github.com/kreuzberg-dev/kreuzberg-lts/issues so we can investigate.\",\n );\n return 1;\n }\n\n const result = spawnSync(cliPath, args, {\n stdio: \"inherit\",\n shell: false,\n });\n\n if (result.error) {\n console.error(`Failed to execute kreuzberg-cli: ${result.error.message}`);\n return 1;\n }\n\n return result.status ?? 1;\n}\n\nif (require.main === module) {\n process.exit(main(process.argv));\n}\n\nexport { main };\n"],"mappings":";;;;;;;;;AAQA,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAC3B,SAAS,SAAS,YAAY;AAC9B,SAAS,qBAAqB;AAC9B,OAAO,WAAW;AAOlB,SAAS,eAAuB;AAC9B,MAAI,OAAO,eAAe,aAAa;AACrC,WAAO,QAAQ,UAAU;AAAA,EAC3B;AACA,MAAI;AACF,UAAM,SAAS,IAAI,SAAS,wBAAwB;AACpD,WAAO,QAAQ,cAAc,OAAO,CAAC,CAAC;AAAA,EACxC,QAAQ;AACN,WAAO,QAAQ,IAAI;AAAA,EACrB;AACF;AAEA,SAAS,KAAK,MAAwB;AACpC,QAAM,OAAO,KAAK,MAAM,CAAC;AAEzB,MAAI;AACJ,MAAI;AACF,cAAU,MAAM,KAAK,eAAe;AAAA,EACtC,QAAQ;AAAA,EAAC;AAET,MAAI,CAAC,SAAS;AACZ,UAAM,YAAY,aAAa;AAC/B,UAAM,YAAY,KAAK,WAAW,MAAM,MAAM,MAAM,UAAU,WAAW,WAAW;AACpF,QAAI,WAAW,SAAS,GAAG;AACzB,gBAAU;AAAA,IACZ;AAAA,EACF;AAEA,MAAI,CAAC,SAAS;AACZ,YAAQ;AAAA,MACN;AAAA,IAGF;AACA,WAAO;AAAA,EACT;AAEA,QAAM,SAAS,UAAU,SAAS,MAAM;AAAA,IACtC,OAAO;AAAA,IACP,OAAO;AAAA,EACT,CAAC;AAED,MAAI,OAAO,OAAO;AAChB,YAAQ,MAAM,oCAAoC,OAAO,MAAM,OAAO,EAAE;AACxE,WAAO;AAAA,EACT;AAEA,SAAO,OAAO,UAAU;AAC1B;AAEA,IAAI,UAAQ,SAAS,QAAQ;AAC3B,UAAQ,KAAK,KAAK,QAAQ,IAAI,CAAC;AACjC;","names":[]}
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../typescript/errors.ts"],"sourcesContent":["/**\n * Error types for Kreuzberg document intelligence framework.\n *\n * These error classes mirror the Rust core error types and provide\n * type-safe error handling for TypeScript consumers.\n *\n * ## Error Hierarchy\n *\n * ```\n * Error (JavaScript built-in)\n * └── KreuzbergError (base class)\n * ├── ValidationError\n * ├── ParsingError\n * ├── OcrError\n * ├── CacheError\n * ├── ImageProcessingError\n * ├── PluginError\n * ├── MissingDependencyError\n * └── ... (other error types)\n * ```\n *\n * @module errors\n */\n\n/**\n * FFI error codes matching kreuzberg-ffi C library error types.\n *\n * @example\n * ```typescript\n * import { ErrorCode, getLastErrorCode } from '@kreuzberg/node';\n *\n * try {\n * const result = await extractFile('document.pdf');\n * } catch (error) {\n * const code = getLastErrorCode();\n * if (code === ErrorCode.Panic) {\n * console.error('A panic occurred in the native library');\n * }\n * }\n * ```\n */\nexport enum ErrorCode {\n\t/**\n\t * No error (success)\n\t */\n\tSuccess = 0,\n\t/**\n\t * Generic error\n\t */\n\tGenericError = 1,\n\t/**\n\t * Panic occurred in native code\n\t */\n\tPanic = 2,\n\t/**\n\t * Invalid argument provided\n\t */\n\tInvalidArgument = 3,\n\t/**\n\t * I/O error (file system, network, etc.)\n\t */\n\tIoError = 4,\n\t/**\n\t * Error parsing document content\n\t */\n\tParsingError = 5,\n\t/**\n\t * Error in OCR processing\n\t */\n\tOcrError = 6,\n\t/**\n\t * Required system dependency is missing\n\t */\n\tMissingDependency = 7,\n\t/**\n\t * Error during embedding generation\n\t */\n\tEmbedding = 8,\n}\n\n/**\n * Context information for panics in native code.\n *\n * Contains file location, line number, function name, panic message,\n * and timestamp for debugging native library issues.\n *\n * @example\n * ```typescript\n * import { KreuzbergError } from '@kreuzberg/node';\n *\n * try {\n * const result = await extractFile('document.pdf');\n * } catch (error) {\n * if (error instanceof KreuzbergError && error.panicContext) {\n * console.error('Panic occurred:');\n * console.error(`File: ${error.panicContext.file}`);\n * console.error(`Line: ${error.panicContext.line}`);\n * console.error(`Function: ${error.panicContext.function}`);\n * console.error(`Message: ${error.panicContext.message}`);\n * }\n * }\n * ```\n */\nexport interface PanicContext {\n\t/**\n\t * Source file where panic occurred\n\t */\n\tfile: string;\n\t/**\n\t * Line number in source file\n\t */\n\tline: number;\n\t/**\n\t * Function name where panic occurred\n\t */\n\tfunction: string;\n\t/**\n\t * Panic message\n\t */\n\tmessage: string;\n\t/**\n\t * Unix timestamp (seconds since epoch)\n\t */\n\ttimestamp_secs: number;\n}\n\n/**\n * Base error class for all Kreuzberg errors.\n *\n * All error types thrown by Kreuzberg extend this class, allowing\n * consumers to catch all Kreuzberg-specific errors with a single catch block.\n *\n * @example\n * ```typescript\n * import { extractFile, KreuzbergError } from '@kreuzberg/node';\n *\n * try {\n * const result = await extractFile('document.pdf');\n * } catch (error) {\n * if (error instanceof KreuzbergError) {\n * console.error('Kreuzberg error:', error.message);\n * if (error.panicContext) {\n * console.error('Panic at:', error.panicContext.file + ':' + error.panicContext.line);\n * }\n * } else {\n * throw error; // Re-throw non-Kreuzberg errors\n * }\n * }\n * ```\n */\nexport class KreuzbergError extends Error {\n\t/**\n\t * Panic context if error was caused by a panic in native code.\n\t * Will be null for non-panic errors.\n\t */\n\tpublic readonly panicContext: PanicContext | null;\n\n\tconstructor(message: string, panicContext?: PanicContext | null) {\n\t\tsuper(message);\n\t\tthis.name = \"KreuzbergError\";\n\t\tthis.panicContext = panicContext ?? null;\n\t\tObject.setPrototypeOf(this, KreuzbergError.prototype);\n\t}\n\n\ttoJSON() {\n\t\treturn {\n\t\t\tname: this.name,\n\t\t\tmessage: this.message,\n\t\t\tpanicContext: this.panicContext,\n\t\t\tstack: this.stack,\n\t\t};\n\t}\n}\n\n/**\n * Error thrown when document validation fails.\n *\n * Validation errors occur when a document doesn't meet specified criteria,\n * such as minimum content length, required metadata fields, or quality thresholds.\n *\n * @example\n * ```typescript\n * import { extractFile, ValidationError } from '@kreuzberg/node';\n *\n * try {\n * const result = await extractFile('document.pdf');\n * } catch (error) {\n * if (error instanceof ValidationError) {\n * console.error('Document validation failed:', error.message);\n * }\n * }\n * ```\n */\nexport class ValidationError extends KreuzbergError {\n\tconstructor(message: string, panicContext?: PanicContext | null) {\n\t\tsuper(message, panicContext);\n\t\tthis.name = \"ValidationError\";\n\t\tObject.setPrototypeOf(this, ValidationError.prototype);\n\t}\n}\n\n/**\n * Error thrown when document parsing fails.\n *\n * Parsing errors occur when a document is corrupted, malformed, or cannot\n * be processed by the extraction engine. This includes issues like:\n * - Corrupted PDF files\n * - Invalid XML/JSON syntax\n * - Unsupported file format versions\n * - Encrypted documents without valid passwords\n *\n * @example\n * ```typescript\n * import { extractFile, ParsingError } from '@kreuzberg/node';\n *\n * try {\n * const result = await extractFile('corrupted.pdf');\n * } catch (error) {\n * if (error instanceof ParsingError) {\n * console.error('Failed to parse document:', error.message);\n * }\n * }\n * ```\n */\nexport class ParsingError extends KreuzbergError {\n\tconstructor(message: string, panicContext?: PanicContext | null) {\n\t\tsuper(message, panicContext);\n\t\tthis.name = \"ParsingError\";\n\t\tObject.setPrototypeOf(this, ParsingError.prototype);\n\t}\n}\n\n/**\n * Error thrown when OCR processing fails.\n *\n * OCR errors occur during optical character recognition, such as:\n * - OCR backend initialization failures\n * - Image preprocessing errors\n * - Language model loading issues\n * - OCR engine crashes\n *\n * @example\n * ```typescript\n * import { extractFile, OcrError } from '@kreuzberg/node';\n *\n * try {\n * const result = await extractFile('scanned.pdf', null, {\n * ocr: { backend: 'tesseract', language: 'eng' }\n * });\n * } catch (error) {\n * if (error instanceof OcrError) {\n * console.error('OCR processing failed:', error.message);\n * }\n * }\n * ```\n */\nexport class OcrError extends KreuzbergError {\n\tconstructor(message: string, panicContext?: PanicContext | null) {\n\t\tsuper(message, panicContext);\n\t\tthis.name = \"OcrError\";\n\t\tObject.setPrototypeOf(this, OcrError.prototype);\n\t}\n}\n\n/**\n * Error thrown when cache operations fail.\n *\n * Cache errors are typically non-fatal and occur during caching operations, such as:\n * - Cache directory creation failures\n * - Disk write errors\n * - Cache entry corruption\n * - Insufficient disk space\n *\n * These errors are usually logged but don't prevent extraction from completing.\n *\n * @example\n * ```typescript\n * import { extractFile, CacheError } from '@kreuzberg/node';\n *\n * try {\n * const result = await extractFile('document.pdf', null, {\n * useCache: true\n * });\n * } catch (error) {\n * if (error instanceof CacheError) {\n * console.warn('Cache operation failed, continuing without cache:', error.message);\n * }\n * }\n * ```\n */\nexport class CacheError extends KreuzbergError {\n\tconstructor(message: string, panicContext?: PanicContext | null) {\n\t\tsuper(message, panicContext);\n\t\tthis.name = \"CacheError\";\n\t\tObject.setPrototypeOf(this, CacheError.prototype);\n\t}\n}\n\n/**\n * Error thrown when image processing operations fail.\n *\n * Image processing errors occur during image manipulation, such as:\n * - Image decoding failures\n * - Unsupported image formats\n * - Image resizing/scaling errors\n * - DPI adjustment failures\n * - Color space conversion issues\n *\n * @example\n * ```typescript\n * import { extractFile, ImageProcessingError } from '@kreuzberg/node';\n *\n * try {\n * const result = await extractFile('document.pdf', null, {\n * images: {\n * extractImages: true,\n * targetDpi: 300\n * }\n * });\n * } catch (error) {\n * if (error instanceof ImageProcessingError) {\n * console.error('Image processing failed:', error.message);\n * }\n * }\n * ```\n */\nexport class ImageProcessingError extends KreuzbergError {\n\tconstructor(message: string, panicContext?: PanicContext | null) {\n\t\tsuper(message, panicContext);\n\t\tthis.name = \"ImageProcessingError\";\n\t\tObject.setPrototypeOf(this, ImageProcessingError.prototype);\n\t}\n}\n\n/**\n * Error thrown when a plugin operation fails.\n *\n * Plugin errors occur in custom plugins (postprocessors, validators, OCR backends), such as:\n * - Plugin initialization failures\n * - Plugin processing errors\n * - Plugin crashes or timeouts\n * - Invalid plugin configuration\n *\n * The error message includes the plugin name to help identify which plugin failed.\n *\n * @example\n * ```typescript\n * import { extractFile, PluginError } from '@kreuzberg/node';\n *\n * try {\n * const result = await extractFile('document.pdf');\n * } catch (error) {\n * if (error instanceof PluginError) {\n * console.error(`Plugin '${error.pluginName}' failed:`, error.message);\n * }\n * }\n * ```\n */\nexport class PluginError extends KreuzbergError {\n\t/**\n\t * Name of the plugin that threw the error.\n\t */\n\tpublic readonly pluginName: string;\n\n\tconstructor(message: string, pluginName: string, panicContext?: PanicContext | null) {\n\t\tsuper(`Plugin error in '${pluginName}': ${message}`, panicContext);\n\t\tthis.name = \"PluginError\";\n\t\tthis.pluginName = pluginName;\n\t\tObject.setPrototypeOf(this, PluginError.prototype);\n\t}\n\n\toverride toJSON() {\n\t\treturn {\n\t\t\tname: this.name,\n\t\t\tmessage: this.message,\n\t\t\tpluginName: this.pluginName,\n\t\t\tpanicContext: this.panicContext,\n\t\t\tstack: this.stack,\n\t\t};\n\t}\n}\n\n/**\n * Error thrown when a required system dependency is missing.\n *\n * Missing dependency errors occur when external tools or libraries are not available, such as:\n * - Tesseract OCR (for OCR processing)\n * - ImageMagick (for image processing)\n * - Poppler (for PDF rendering)\n *\n * @example\n * ```typescript\n * import { extractFile, MissingDependencyError } from '@kreuzberg/node';\n *\n * try {\n * const result = await extractFile('document.pdf');\n * } catch (error) {\n * if (error instanceof MissingDependencyError) {\n * console.error('Missing dependency:', error.message);\n * console.log('Please install Tesseract OCR for image processing');\n * }\n * }\n * ```\n */\nexport class MissingDependencyError extends KreuzbergError {\n\tconstructor(message: string, panicContext?: PanicContext | null) {\n\t\tsuper(message, panicContext);\n\t\tthis.name = \"MissingDependencyError\";\n\t\tObject.setPrototypeOf(this, MissingDependencyError.prototype);\n\t}\n}\n\n/**\n * Error thrown when text embedding generation fails.\n *\n * Embedding errors occur during vector generation, such as:\n * - Model loading failures\n * - Inference engine errors\n * - Invalid input text for the selected model\n * - Resource exhaustion during batch processing\n *\n * @example\n * ```typescript\n * import { embed, EmbeddingError } from '@kreuzberg/node';\n *\n * try {\n * const result = await embed(['hello world']);\n * } catch (error) {\n * if (error instanceof EmbeddingError) {\n * console.error('Embedding generation failed:', error.message);\n * }\n * }\n * ```\n */\nexport class EmbeddingError extends KreuzbergError {\n\tconstructor(message: string, panicContext?: PanicContext | null) {\n\t\tsuper(message, panicContext);\n\t\tthis.name = \"EmbeddingError\";\n\t\tObject.setPrototypeOf(this, EmbeddingError.prototype);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAyCO,IAAK,YAAL,kBAAKA,eAAL;AAIN,EAAAA,sBAAA,aAAU,KAAV;AAIA,EAAAA,sBAAA,kBAAe,KAAf;AAIA,EAAAA,sBAAA,WAAQ,KAAR;AAIA,EAAAA,sBAAA,qBAAkB,KAAlB;AAIA,EAAAA,sBAAA,aAAU,KAAV;AAIA,EAAAA,sBAAA,kBAAe,KAAf;AAIA,EAAAA,sBAAA,cAAW,KAAX;AAIA,EAAAA,sBAAA,uBAAoB,KAApB;AAIA,EAAAA,sBAAA,eAAY,KAAZ;AApCW,SAAAA;AAAA,GAAA;AA6GL,IAAM,iBAAN,MAAM,wBAAuB,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA,EAKzB;AAAA,EAEhB,YAAY,SAAiB,cAAoC;AAChE,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,eAAe,gBAAgB;AACpC,WAAO,eAAe,MAAM,gBAAe,SAAS;AAAA,EACrD;AAAA,EAEA,SAAS;AACR,WAAO;AAAA,MACN,MAAM,KAAK;AAAA,MACX,SAAS,KAAK;AAAA,MACd,cAAc,KAAK;AAAA,MACnB,OAAO,KAAK;AAAA,IACb;AAAA,EACD;AACD;AAqBO,IAAM,kBAAN,MAAM,yBAAwB,eAAe;AAAA,EACnD,YAAY,SAAiB,cAAoC;AAChE,UAAM,SAAS,YAAY;AAC3B,SAAK,OAAO;AACZ,WAAO,eAAe,MAAM,iBAAgB,SAAS;AAAA,EACtD;AACD;AAyB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MAAM,wBAAuB,SAAS;AAAA,EAC7D;AACD;AAwBO,IAAM,iBAAN,MAAM,wBAAuB,eAAe;AAAA,EAClD,YAAY,SAAiB,cAAoC;AAChE,UAAM,SAAS,YAAY;AAC3B,SAAK,OAAO;AACZ,WAAO,eAAe,MAAM,gBAAe,SAAS;AAAA,EACrD;AACD;","names":["ErrorCode"]}
|
|
1
|
+
{"version":3,"sources":["../typescript/errors.ts"],"sourcesContent":["/**\n * Error types for Kreuzberg document intelligence framework.\n *\n * These error classes mirror the Rust core error types and provide\n * type-safe error handling for TypeScript consumers.\n *\n * ## Error Hierarchy\n *\n * ```\n * Error (JavaScript built-in)\n * └── KreuzbergError (base class)\n * ├── ValidationError\n * ├── ParsingError\n * ├── OcrError\n * ├── CacheError\n * ├── ImageProcessingError\n * ├── PluginError\n * ├── MissingDependencyError\n * └── ... (other error types)\n * ```\n *\n * @module errors\n */\n\n/**\n * FFI error codes matching kreuzberg-ffi C library error types.\n *\n * @example\n * ```typescript\n * import { ErrorCode, getLastErrorCode } from '@kreuzberg/node';\n *\n * try {\n * const result = await extractFile('document.pdf');\n * } catch (error) {\n * const code = getLastErrorCode();\n * if (code === ErrorCode.Panic) {\n * console.error('A panic occurred in the native library');\n * }\n * }\n * ```\n */\nexport enum ErrorCode {\n /**\n * No error (success)\n */\n Success = 0,\n /**\n * Generic error\n */\n GenericError = 1,\n /**\n * Panic occurred in native code\n */\n Panic = 2,\n /**\n * Invalid argument provided\n */\n InvalidArgument = 3,\n /**\n * I/O error (file system, network, etc.)\n */\n IoError = 4,\n /**\n * Error parsing document content\n */\n ParsingError = 5,\n /**\n * Error in OCR processing\n */\n OcrError = 6,\n /**\n * Required system dependency is missing\n */\n MissingDependency = 7,\n /**\n * Error during embedding generation\n */\n Embedding = 8,\n}\n\n/**\n * Context information for panics in native code.\n *\n * Contains file location, line number, function name, panic message,\n * and timestamp for debugging native library issues.\n *\n * @example\n * ```typescript\n * import { KreuzbergError } from '@kreuzberg/node';\n *\n * try {\n * const result = await extractFile('document.pdf');\n * } catch (error) {\n * if (error instanceof KreuzbergError && error.panicContext) {\n * console.error('Panic occurred:');\n * console.error(`File: ${error.panicContext.file}`);\n * console.error(`Line: ${error.panicContext.line}`);\n * console.error(`Function: ${error.panicContext.function}`);\n * console.error(`Message: ${error.panicContext.message}`);\n * }\n * }\n * ```\n */\nexport interface PanicContext {\n /**\n * Source file where panic occurred\n */\n file: string;\n /**\n * Line number in source file\n */\n line: number;\n /**\n * Function name where panic occurred\n */\n function: string;\n /**\n * Panic message\n */\n message: string;\n /**\n * Unix timestamp (seconds since epoch)\n */\n timestamp_secs: number;\n}\n\n/**\n * Base error class for all Kreuzberg errors.\n *\n * All error types thrown by Kreuzberg extend this class, allowing\n * consumers to catch all Kreuzberg-specific errors with a single catch block.\n *\n * @example\n * ```typescript\n * import { extractFile, KreuzbergError } from '@kreuzberg/node';\n *\n * try {\n * const result = await extractFile('document.pdf');\n * } catch (error) {\n * if (error instanceof KreuzbergError) {\n * console.error('Kreuzberg error:', error.message);\n * if (error.panicContext) {\n * console.error('Panic at:', error.panicContext.file + ':' + error.panicContext.line);\n * }\n * } else {\n * throw error; // Re-throw non-Kreuzberg errors\n * }\n * }\n * ```\n */\nexport class KreuzbergError extends Error {\n /**\n * Panic context if error was caused by a panic in native code.\n * Will be null for non-panic errors.\n */\n public readonly panicContext: PanicContext | null;\n\n constructor(message: string, panicContext?: PanicContext | null) {\n super(message);\n this.name = \"KreuzbergError\";\n this.panicContext = panicContext ?? null;\n Object.setPrototypeOf(this, KreuzbergError.prototype);\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n panicContext: this.panicContext,\n stack: this.stack,\n };\n }\n}\n\n/**\n * Error thrown when document validation fails.\n *\n * Validation errors occur when a document doesn't meet specified criteria,\n * such as minimum content length, required metadata fields, or quality thresholds.\n *\n * @example\n * ```typescript\n * import { extractFile, ValidationError } from '@kreuzberg/node';\n *\n * try {\n * const result = await extractFile('document.pdf');\n * } catch (error) {\n * if (error instanceof ValidationError) {\n * console.error('Document validation failed:', error.message);\n * }\n * }\n * ```\n */\nexport class ValidationError extends KreuzbergError {\n constructor(message: string, panicContext?: PanicContext | null) {\n super(message, panicContext);\n this.name = \"ValidationError\";\n Object.setPrototypeOf(this, ValidationError.prototype);\n }\n}\n\n/**\n * Error thrown when document parsing fails.\n *\n * Parsing errors occur when a document is corrupted, malformed, or cannot\n * be processed by the extraction engine. This includes issues like:\n * - Corrupted PDF files\n * - Invalid XML/JSON syntax\n * - Unsupported file format versions\n * - Encrypted documents without valid passwords\n *\n * @example\n * ```typescript\n * import { extractFile, ParsingError } from '@kreuzberg/node';\n *\n * try {\n * const result = await extractFile('corrupted.pdf');\n * } catch (error) {\n * if (error instanceof ParsingError) {\n * console.error('Failed to parse document:', error.message);\n * }\n * }\n * ```\n */\nexport class ParsingError extends KreuzbergError {\n constructor(message: string, panicContext?: PanicContext | null) {\n super(message, panicContext);\n this.name = \"ParsingError\";\n Object.setPrototypeOf(this, ParsingError.prototype);\n }\n}\n\n/**\n * Error thrown when OCR processing fails.\n *\n * OCR errors occur during optical character recognition, such as:\n * - OCR backend initialization failures\n * - Image preprocessing errors\n * - Language model loading issues\n * - OCR engine crashes\n *\n * @example\n * ```typescript\n * import { extractFile, OcrError } from '@kreuzberg/node';\n *\n * try {\n * const result = await extractFile('scanned.pdf', null, {\n * ocr: { backend: 'tesseract', language: 'eng' }\n * });\n * } catch (error) {\n * if (error instanceof OcrError) {\n * console.error('OCR processing failed:', error.message);\n * }\n * }\n * ```\n */\nexport class OcrError extends KreuzbergError {\n constructor(message: string, panicContext?: PanicContext | null) {\n super(message, panicContext);\n this.name = \"OcrError\";\n Object.setPrototypeOf(this, OcrError.prototype);\n }\n}\n\n/**\n * Error thrown when cache operations fail.\n *\n * Cache errors are typically non-fatal and occur during caching operations, such as:\n * - Cache directory creation failures\n * - Disk write errors\n * - Cache entry corruption\n * - Insufficient disk space\n *\n * These errors are usually logged but don't prevent extraction from completing.\n *\n * @example\n * ```typescript\n * import { extractFile, CacheError } from '@kreuzberg/node';\n *\n * try {\n * const result = await extractFile('document.pdf', null, {\n * useCache: true\n * });\n * } catch (error) {\n * if (error instanceof CacheError) {\n * console.warn('Cache operation failed, continuing without cache:', error.message);\n * }\n * }\n * ```\n */\nexport class CacheError extends KreuzbergError {\n constructor(message: string, panicContext?: PanicContext | null) {\n super(message, panicContext);\n this.name = \"CacheError\";\n Object.setPrototypeOf(this, CacheError.prototype);\n }\n}\n\n/**\n * Error thrown when image processing operations fail.\n *\n * Image processing errors occur during image manipulation, such as:\n * - Image decoding failures\n * - Unsupported image formats\n * - Image resizing/scaling errors\n * - DPI adjustment failures\n * - Color space conversion issues\n *\n * @example\n * ```typescript\n * import { extractFile, ImageProcessingError } from '@kreuzberg/node';\n *\n * try {\n * const result = await extractFile('document.pdf', null, {\n * images: {\n * extractImages: true,\n * targetDpi: 300\n * }\n * });\n * } catch (error) {\n * if (error instanceof ImageProcessingError) {\n * console.error('Image processing failed:', error.message);\n * }\n * }\n * ```\n */\nexport class ImageProcessingError extends KreuzbergError {\n constructor(message: string, panicContext?: PanicContext | null) {\n super(message, panicContext);\n this.name = \"ImageProcessingError\";\n Object.setPrototypeOf(this, ImageProcessingError.prototype);\n }\n}\n\n/**\n * Error thrown when a plugin operation fails.\n *\n * Plugin errors occur in custom plugins (postprocessors, validators, OCR backends), such as:\n * - Plugin initialization failures\n * - Plugin processing errors\n * - Plugin crashes or timeouts\n * - Invalid plugin configuration\n *\n * The error message includes the plugin name to help identify which plugin failed.\n *\n * @example\n * ```typescript\n * import { extractFile, PluginError } from '@kreuzberg/node';\n *\n * try {\n * const result = await extractFile('document.pdf');\n * } catch (error) {\n * if (error instanceof PluginError) {\n * console.error(`Plugin '${error.pluginName}' failed:`, error.message);\n * }\n * }\n * ```\n */\nexport class PluginError extends KreuzbergError {\n /**\n * Name of the plugin that threw the error.\n */\n public readonly pluginName: string;\n\n constructor(message: string, pluginName: string, panicContext?: PanicContext | null) {\n super(`Plugin error in '${pluginName}': ${message}`, panicContext);\n this.name = \"PluginError\";\n this.pluginName = pluginName;\n Object.setPrototypeOf(this, PluginError.prototype);\n }\n\n override toJSON() {\n return {\n name: this.name,\n message: this.message,\n pluginName: this.pluginName,\n panicContext: this.panicContext,\n stack: this.stack,\n };\n }\n}\n\n/**\n * Error thrown when a required system dependency is missing.\n *\n * Missing dependency errors occur when external tools or libraries are not available, such as:\n * - Tesseract OCR (for OCR processing)\n * - ImageMagick (for image processing)\n * - Poppler (for PDF rendering)\n *\n * @example\n * ```typescript\n * import { extractFile, MissingDependencyError } from '@kreuzberg/node';\n *\n * try {\n * const result = await extractFile('document.pdf');\n * } catch (error) {\n * if (error instanceof MissingDependencyError) {\n * console.error('Missing dependency:', error.message);\n * console.log('Please install Tesseract OCR for image processing');\n * }\n * }\n * ```\n */\nexport class MissingDependencyError extends KreuzbergError {\n constructor(message: string, panicContext?: PanicContext | null) {\n super(message, panicContext);\n this.name = \"MissingDependencyError\";\n Object.setPrototypeOf(this, MissingDependencyError.prototype);\n }\n}\n\n/**\n * Error thrown when text embedding generation fails.\n *\n * Embedding errors occur during vector generation, such as:\n * - Model loading failures\n * - Inference engine errors\n * - Invalid input text for the selected model\n * - Resource exhaustion during batch processing\n *\n * @example\n * ```typescript\n * import { embed, EmbeddingError } from '@kreuzberg/node';\n *\n * try {\n * const result = await embed(['hello world']);\n * } catch (error) {\n * if (error instanceof EmbeddingError) {\n * console.error('Embedding generation failed:', error.message);\n * }\n * }\n * ```\n */\nexport class EmbeddingError extends KreuzbergError {\n constructor(message: string, panicContext?: PanicContext | null) {\n super(message, panicContext);\n this.name = \"EmbeddingError\";\n Object.setPrototypeOf(this, EmbeddingError.prototype);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAyCO,IAAK,YAAL,kBAAKA,eAAL;AAIL,EAAAA,s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B,eAAe;AAAA,EAC7C,YAAY,SAAiB,cAAoC;AAC/D,UAAM,SAAS,YAAY;AAC3B,SAAK,OAAO;AACZ,WAAO,eAAe,MAAM,YAAW,SAAS;AAAA,EAClD;AACF;AA8BO,IAAM,uBAAN,MAAM,8BAA6B,eAAe;AAAA,EACvD,YAAY,SAAiB,cAAoC;AAC/D,UAAM,SAAS,YAAY;AAC3B,SAAK,OAAO;AACZ,WAAO,eAAe,MAAM,sBAAqB,SAAS;AAAA,EAC5D;AACF;AA0BO,IAAM,cAAN,MAAM,qBAAoB,eAAe;AAAA;AAAA;AAAA;AAAA,EAI9B;AAAA,EAEhB,YAAY,SAAiB,YAAoB,cAAoC;AACnF,UAAM,oBAAoB,UAAU,MAAM,OAAO,IAAI,YAAY;AACjE,SAAK,OAAO;AACZ,SAAK,aAAa;AAClB,WAAO,eAAe,MAAM,aAAY,SAAS;AAAA,EACnD;AAAA,EAES,SAAS;AAChB,WAAO;AAAA,MACL,MAAM,KAAK;AAAA,MACX,SAAS,KAAK;AAAA,MACd,YAAY,KAAK;AAAA,MACjB,cAAc,KAAK;AAAA,MACnB,OAAO,KAAK;AAAA,IACd;AAAA,EACF;AACF;AAwBO,IAAM,yBAAN,MAAM,gCAA+B,eAAe;AAAA,EACzD,YAAY,SAAiB,cAAoC;AAC/D,UAAM,SAAS,YAAY;AAC3B,SAAK,OAAO;AACZ,WAAO,eAAe,MAAM,wBAAuB,SAAS;AAAA,EAC9D;AACF;AAwBO,IAAM,iBAAN,MAAM,wBAAuB,eAAe;AAAA,EACjD,YAAY,SAAiB,cAAoC;AAC/D,UAAM,SAAS,YAAY;AAC3B,SAAK,OAAO;AACZ,WAAO,eAAe,MAAM,gBAAe,SAAS;AAAA,EACtD;AACF;","names":["ErrorCode"]}
|
package/dist/errors.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../typescript/errors.ts"],"sourcesContent":["/**\n * Error types for Kreuzberg document intelligence framework.\n *\n * These error classes mirror the Rust core error types and provide\n * type-safe error handling for TypeScript consumers.\n *\n * ## Error Hierarchy\n *\n * ```\n * Error (JavaScript built-in)\n * └── KreuzbergError (base class)\n * ├── ValidationError\n * ├── ParsingError\n * ├── OcrError\n * ├── CacheError\n * ├── ImageProcessingError\n * ├── PluginError\n * ├── MissingDependencyError\n * └── ... (other error types)\n * ```\n *\n * @module errors\n */\n\n/**\n * FFI error codes matching kreuzberg-ffi C library error types.\n *\n * @example\n * ```typescript\n * import { ErrorCode, getLastErrorCode } from '@kreuzberg/node';\n *\n * try {\n * const result = await extractFile('document.pdf');\n * } catch (error) {\n * const code = getLastErrorCode();\n * if (code === ErrorCode.Panic) {\n * console.error('A panic occurred in the native library');\n * }\n * }\n * ```\n */\nexport enum ErrorCode {\n\t/**\n\t * No error (success)\n\t */\n\tSuccess = 0,\n\t/**\n\t * Generic error\n\t */\n\tGenericError = 1,\n\t/**\n\t * Panic occurred in native code\n\t */\n\tPanic = 2,\n\t/**\n\t * Invalid argument provided\n\t */\n\tInvalidArgument = 3,\n\t/**\n\t * I/O error (file system, network, etc.)\n\t */\n\tIoError = 4,\n\t/**\n\t * Error parsing document content\n\t */\n\tParsingError = 5,\n\t/**\n\t * Error in OCR processing\n\t */\n\tOcrError = 6,\n\t/**\n\t * Required system dependency is missing\n\t */\n\tMissingDependency = 7,\n\t/**\n\t * Error during embedding generation\n\t */\n\tEmbedding = 8,\n}\n\n/**\n * Context information for panics in native code.\n *\n * Contains file location, line number, function name, panic message,\n * and timestamp for debugging native library issues.\n *\n * @example\n * ```typescript\n * import { KreuzbergError } from '@kreuzberg/node';\n *\n * try {\n * const result = await extractFile('document.pdf');\n * } catch (error) {\n * if (error instanceof KreuzbergError && error.panicContext) {\n * console.error('Panic occurred:');\n * console.error(`File: ${error.panicContext.file}`);\n * console.error(`Line: ${error.panicContext.line}`);\n * console.error(`Function: ${error.panicContext.function}`);\n * console.error(`Message: ${error.panicContext.message}`);\n * }\n * }\n * ```\n */\nexport interface PanicContext {\n\t/**\n\t * Source file where panic occurred\n\t */\n\tfile: string;\n\t/**\n\t * Line number in source file\n\t */\n\tline: number;\n\t/**\n\t * Function name where panic occurred\n\t */\n\tfunction: string;\n\t/**\n\t * Panic message\n\t */\n\tmessage: string;\n\t/**\n\t * Unix timestamp (seconds since epoch)\n\t */\n\ttimestamp_secs: number;\n}\n\n/**\n * Base error class for all Kreuzberg errors.\n *\n * All error types thrown by Kreuzberg extend this class, allowing\n * consumers to catch all Kreuzberg-specific errors with a single catch block.\n *\n * @example\n * ```typescript\n * import { extractFile, KreuzbergError } from '@kreuzberg/node';\n *\n * try {\n * const result = await extractFile('document.pdf');\n * } catch (error) {\n * if (error instanceof KreuzbergError) {\n * console.error('Kreuzberg error:', error.message);\n * if (error.panicContext) {\n * console.error('Panic at:', error.panicContext.file + ':' + error.panicContext.line);\n * }\n * } else {\n * throw error; // Re-throw non-Kreuzberg errors\n * }\n * }\n * ```\n */\nexport class KreuzbergError extends Error {\n\t/**\n\t * Panic context if error was caused by a panic in native code.\n\t * Will be null for non-panic errors.\n\t */\n\tpublic readonly panicContext: PanicContext | null;\n\n\tconstructor(message: string, panicContext?: PanicContext | null) {\n\t\tsuper(message);\n\t\tthis.name = \"KreuzbergError\";\n\t\tthis.panicContext = panicContext ?? null;\n\t\tObject.setPrototypeOf(this, KreuzbergError.prototype);\n\t}\n\n\ttoJSON() {\n\t\treturn {\n\t\t\tname: this.name,\n\t\t\tmessage: this.message,\n\t\t\tpanicContext: this.panicContext,\n\t\t\tstack: this.stack,\n\t\t};\n\t}\n}\n\n/**\n * Error thrown when document validation fails.\n *\n * Validation errors occur when a document doesn't meet specified criteria,\n * such as minimum content length, required metadata fields, or quality thresholds.\n *\n * @example\n * ```typescript\n * import { extractFile, ValidationError } from '@kreuzberg/node';\n *\n * try {\n * const result = await extractFile('document.pdf');\n * } catch (error) {\n * if (error instanceof ValidationError) {\n * console.error('Document validation failed:', error.message);\n * }\n * }\n * ```\n */\nexport class ValidationError extends KreuzbergError {\n\tconstructor(message: string, panicContext?: PanicContext | null) {\n\t\tsuper(message, panicContext);\n\t\tthis.name = \"ValidationError\";\n\t\tObject.setPrototypeOf(this, ValidationError.prototype);\n\t}\n}\n\n/**\n * Error thrown when document parsing fails.\n *\n * Parsing errors occur when a document is corrupted, malformed, or cannot\n * be processed by the extraction engine. This includes issues like:\n * - Corrupted PDF files\n * - Invalid XML/JSON syntax\n * - Unsupported file format versions\n * - Encrypted documents without valid passwords\n *\n * @example\n * ```typescript\n * import { extractFile, ParsingError } from '@kreuzberg/node';\n *\n * try {\n * const result = await extractFile('corrupted.pdf');\n * } catch (error) {\n * if (error instanceof ParsingError) {\n * console.error('Failed to parse document:', error.message);\n * }\n * }\n * ```\n */\nexport class ParsingError extends KreuzbergError {\n\tconstructor(message: string, panicContext?: PanicContext | null) {\n\t\tsuper(message, panicContext);\n\t\tthis.name = \"ParsingError\";\n\t\tObject.setPrototypeOf(this, ParsingError.prototype);\n\t}\n}\n\n/**\n * Error thrown when OCR processing fails.\n *\n * OCR errors occur during optical character recognition, such as:\n * - OCR backend initialization failures\n * - Image preprocessing errors\n * - Language model loading issues\n * - OCR engine crashes\n *\n * @example\n * ```typescript\n * import { extractFile, OcrError } from '@kreuzberg/node';\n *\n * try {\n * const result = await extractFile('scanned.pdf', null, {\n * ocr: { backend: 'tesseract', language: 'eng' }\n * });\n * } catch (error) {\n * if (error instanceof OcrError) {\n * console.error('OCR processing failed:', error.message);\n * }\n * }\n * ```\n */\nexport class OcrError extends KreuzbergError {\n\tconstructor(message: string, panicContext?: PanicContext | null) {\n\t\tsuper(message, panicContext);\n\t\tthis.name = \"OcrError\";\n\t\tObject.setPrototypeOf(this, OcrError.prototype);\n\t}\n}\n\n/**\n * Error thrown when cache operations fail.\n *\n * Cache errors are typically non-fatal and occur during caching operations, such as:\n * - Cache directory creation failures\n * - Disk write errors\n * - Cache entry corruption\n * - Insufficient disk space\n *\n * These errors are usually logged but don't prevent extraction from completing.\n *\n * @example\n * ```typescript\n * import { extractFile, CacheError } from '@kreuzberg/node';\n *\n * try {\n * const result = await extractFile('document.pdf', null, {\n * useCache: true\n * });\n * } catch (error) {\n * if (error instanceof CacheError) {\n * console.warn('Cache operation failed, continuing without cache:', error.message);\n * }\n * }\n * ```\n */\nexport class CacheError extends KreuzbergError {\n\tconstructor(message: string, panicContext?: PanicContext | null) {\n\t\tsuper(message, panicContext);\n\t\tthis.name = \"CacheError\";\n\t\tObject.setPrototypeOf(this, CacheError.prototype);\n\t}\n}\n\n/**\n * Error thrown when image processing operations fail.\n *\n * Image processing errors occur during image manipulation, such as:\n * - Image decoding failures\n * - Unsupported image formats\n * - Image resizing/scaling errors\n * - DPI adjustment failures\n * - Color space conversion issues\n *\n * @example\n * ```typescript\n * import { extractFile, ImageProcessingError } from '@kreuzberg/node';\n *\n * try {\n * const result = await extractFile('document.pdf', null, {\n * images: {\n * extractImages: true,\n * targetDpi: 300\n * }\n * });\n * } catch (error) {\n * if (error instanceof ImageProcessingError) {\n * console.error('Image processing failed:', error.message);\n * }\n * }\n * ```\n */\nexport class ImageProcessingError extends KreuzbergError {\n\tconstructor(message: string, panicContext?: PanicContext | null) {\n\t\tsuper(message, panicContext);\n\t\tthis.name = \"ImageProcessingError\";\n\t\tObject.setPrototypeOf(this, ImageProcessingError.prototype);\n\t}\n}\n\n/**\n * Error thrown when a plugin operation fails.\n *\n * Plugin errors occur in custom plugins (postprocessors, validators, OCR backends), such as:\n * - Plugin initialization failures\n * - Plugin processing errors\n * - Plugin crashes or timeouts\n * - Invalid plugin configuration\n *\n * The error message includes the plugin name to help identify which plugin failed.\n *\n * @example\n * ```typescript\n * import { extractFile, PluginError } from '@kreuzberg/node';\n *\n * try {\n * const result = await extractFile('document.pdf');\n * } catch (error) {\n * if (error instanceof PluginError) {\n * console.error(`Plugin '${error.pluginName}' failed:`, error.message);\n * }\n * }\n * ```\n */\nexport class PluginError extends KreuzbergError {\n\t/**\n\t * Name of the plugin that threw the error.\n\t */\n\tpublic readonly pluginName: string;\n\n\tconstructor(message: string, pluginName: string, panicContext?: PanicContext | null) {\n\t\tsuper(`Plugin error in '${pluginName}': ${message}`, panicContext);\n\t\tthis.name = \"PluginError\";\n\t\tthis.pluginName = pluginName;\n\t\tObject.setPrototypeOf(this, PluginError.prototype);\n\t}\n\n\toverride toJSON() {\n\t\treturn {\n\t\t\tname: this.name,\n\t\t\tmessage: this.message,\n\t\t\tpluginName: this.pluginName,\n\t\t\tpanicContext: this.panicContext,\n\t\t\tstack: this.stack,\n\t\t};\n\t}\n}\n\n/**\n * Error thrown when a required system dependency is missing.\n *\n * Missing dependency errors occur when external tools or libraries are not available, such as:\n * - Tesseract OCR (for OCR processing)\n * - ImageMagick (for image processing)\n * - Poppler (for PDF rendering)\n *\n * @example\n * ```typescript\n * import { extractFile, MissingDependencyError } from '@kreuzberg/node';\n *\n * try {\n * const result = await extractFile('document.pdf');\n * } catch (error) {\n * if (error instanceof MissingDependencyError) {\n * console.error('Missing dependency:', error.message);\n * console.log('Please install Tesseract OCR for image processing');\n * }\n * }\n * ```\n */\nexport class MissingDependencyError extends KreuzbergError {\n\tconstructor(message: string, panicContext?: PanicContext | null) {\n\t\tsuper(message, panicContext);\n\t\tthis.name = \"MissingDependencyError\";\n\t\tObject.setPrototypeOf(this, MissingDependencyError.prototype);\n\t}\n}\n\n/**\n * Error thrown when text embedding generation fails.\n *\n * Embedding errors occur during vector generation, such as:\n * - Model loading failures\n * - Inference engine errors\n * - Invalid input text for the selected model\n * - Resource exhaustion during batch processing\n *\n * @example\n * ```typescript\n * import { embed, EmbeddingError } from '@kreuzberg/node';\n *\n * try {\n * const result = await embed(['hello world']);\n * } catch (error) {\n * if (error instanceof EmbeddingError) {\n * console.error('Embedding generation failed:', error.message);\n * }\n * }\n * ```\n */\nexport class EmbeddingError extends KreuzbergError {\n\tconstructor(message: string, panicContext?: PanicContext | null) {\n\t\tsuper(message, panicContext);\n\t\tthis.name = \"EmbeddingError\";\n\t\tObject.setPrototypeOf(this, Em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kreuzberg document intelligence framework.\n *\n * These error classes mirror the Rust core error types and provide\n * type-safe error handling for TypeScript consumers.\n *\n * ## Error Hierarchy\n *\n * ```\n * Error (JavaScript built-in)\n * └── KreuzbergError (base class)\n * ├── ValidationError\n * ├── ParsingError\n * ├── OcrError\n * ├── CacheError\n * ├── ImageProcessingError\n * ├── PluginError\n * ├── MissingDependencyError\n * └── ... (other error types)\n * ```\n *\n * @module errors\n */\n\n/**\n * FFI error codes matching kreuzberg-ffi C library error types.\n *\n * @example\n * ```typescript\n * import { ErrorCode, getLastErrorCode } from '@kreuzberg/node';\n *\n * try {\n * const result = await extractFile('document.pdf');\n * } catch (error) {\n * const code = getLastErrorCode();\n * if (code === ErrorCode.Panic) {\n * console.error('A panic occurred in the native library');\n * }\n * }\n * ```\n */\nexport enum ErrorCode {\n /**\n * No error (success)\n */\n Success = 0,\n /**\n * Generic error\n */\n GenericError = 1,\n /**\n * Panic occurred in native code\n */\n Panic = 2,\n /**\n * Invalid argument provided\n */\n InvalidArgument = 3,\n /**\n * I/O error (file system, network, etc.)\n */\n IoError = 4,\n /**\n * Error parsing document content\n */\n ParsingError = 5,\n /**\n * Error in OCR processing\n */\n OcrError = 6,\n /**\n * Required system dependency is missing\n */\n MissingDependency = 7,\n /**\n * Error during embedding generation\n */\n Embedding = 8,\n}\n\n/**\n * Context information for panics in native code.\n *\n * Contains file location, line number, function name, panic message,\n * and timestamp for debugging native library issues.\n *\n * @example\n * ```typescript\n * import { KreuzbergError } from '@kreuzberg/node';\n *\n * try {\n * const result = await extractFile('document.pdf');\n * } catch (error) {\n * if (error instanceof KreuzbergError && error.panicContext) {\n * console.error('Panic occurred:');\n * console.error(`File: ${error.panicContext.file}`);\n * console.error(`Line: ${error.panicContext.line}`);\n * console.error(`Function: ${error.panicContext.function}`);\n * console.error(`Message: ${error.panicContext.message}`);\n * }\n * }\n * ```\n */\nexport interface PanicContext {\n /**\n * Source file where panic occurred\n */\n file: string;\n /**\n * Line number in source file\n */\n line: number;\n /**\n * Function name where panic occurred\n */\n function: string;\n /**\n * Panic message\n */\n message: string;\n /**\n * Unix timestamp (seconds since epoch)\n */\n timestamp_secs: number;\n}\n\n/**\n * Base error class for all Kreuzberg errors.\n *\n * All error types thrown by Kreuzberg extend this class, allowing\n * consumers to catch all Kreuzberg-specific errors with a single catch block.\n *\n * @example\n * ```typescript\n * import { extractFile, KreuzbergError } from '@kreuzberg/node';\n *\n * try {\n * const result = await extractFile('document.pdf');\n * } catch (error) {\n * if (error instanceof KreuzbergError) {\n * console.error('Kreuzberg error:', error.message);\n * if (error.panicContext) {\n * console.error('Panic at:', error.panicContext.file + ':' + error.panicContext.line);\n * }\n * } else {\n * throw error; // Re-throw non-Kreuzberg errors\n * }\n * }\n * ```\n */\nexport class KreuzbergError extends Error {\n /**\n * Panic context if error was caused by a panic in native code.\n * Will be null for non-panic errors.\n */\n public readonly panicContext: PanicContext | null;\n\n constructor(message: string, panicContext?: PanicContext | null) {\n super(message);\n this.name = \"KreuzbergError\";\n this.panicContext = panicContext ?? null;\n Object.setPrototypeOf(this, KreuzbergError.prototype);\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n panicContext: this.panicContext,\n stack: this.stack,\n };\n }\n}\n\n/**\n * Error thrown when document validation fails.\n *\n * Validation errors occur when a document doesn't meet specified criteria,\n * such as minimum content length, required metadata fields, or quality thresholds.\n *\n * @example\n * ```typescript\n * import { extractFile, ValidationError } from '@kreuzberg/node';\n *\n * try {\n * const result = await extractFile('document.pdf');\n * } catch (error) {\n * if (error instanceof ValidationError) {\n * console.error('Document validation failed:', error.message);\n * }\n * }\n * ```\n */\nexport class ValidationError extends KreuzbergError {\n constructor(message: string, panicContext?: PanicContext | null) {\n super(message, panicContext);\n this.name = \"ValidationError\";\n Object.setPrototypeOf(this, ValidationError.prototype);\n }\n}\n\n/**\n * Error thrown when document parsing fails.\n *\n * Parsing errors occur when a document is corrupted, malformed, or cannot\n * be processed by the extraction engine. This includes issues like:\n * - Corrupted PDF files\n * - Invalid XML/JSON syntax\n * - Unsupported file format versions\n * - Encrypted documents without valid passwords\n *\n * @example\n * ```typescript\n * import { extractFile, ParsingError } from '@kreuzberg/node';\n *\n * try {\n * const result = await extractFile('corrupted.pdf');\n * } catch (error) {\n * if (error instanceof ParsingError) {\n * console.error('Failed to parse document:', error.message);\n * }\n * }\n * ```\n */\nexport class ParsingError extends KreuzbergError {\n constructor(message: string, panicContext?: PanicContext | null) {\n super(message, panicContext);\n this.name = \"ParsingError\";\n Object.setPrototypeOf(this, ParsingError.prototype);\n }\n}\n\n/**\n * Error thrown when OCR processing fails.\n *\n * OCR errors occur during optical character recognition, such as:\n * - OCR backend initialization failures\n * - Image preprocessing errors\n * - Language model loading issues\n * - OCR engine crashes\n *\n * @example\n * ```typescript\n * import { extractFile, OcrError } from '@kreuzberg/node';\n *\n * try {\n * const result = await extractFile('scanned.pdf', null, {\n * ocr: { backend: 'tesseract', language: 'eng' }\n * });\n * } catch (error) {\n * if (error instanceof OcrError) {\n * console.error('OCR processing failed:', error.message);\n * }\n * }\n * ```\n */\nexport class OcrError extends KreuzbergError {\n constructor(message: string, panicContext?: PanicContext | null) {\n super(message, panicContext);\n this.name = \"OcrError\";\n Object.setPrototypeOf(this, OcrError.prototype);\n }\n}\n\n/**\n * Error thrown when cache operations fail.\n *\n * Cache errors are typically non-fatal and occur during caching operations, such as:\n * - Cache directory creation failures\n * - Disk write errors\n * - Cache entry corruption\n * - Insufficient disk space\n *\n * These errors are usually logged but don't prevent extraction from completing.\n *\n * @example\n * ```typescript\n * import { extractFile, CacheError } from '@kreuzberg/node';\n *\n * try {\n * const result = await extractFile('document.pdf', null, {\n * useCache: true\n * });\n * } catch (error) {\n * if (error instanceof CacheError) {\n * console.warn('Cache operation failed, continuing without cache:', error.message);\n * }\n * }\n * ```\n */\nexport class CacheError extends KreuzbergError {\n constructor(message: string, panicContext?: PanicContext | null) {\n super(message, panicContext);\n this.name = \"CacheError\";\n Object.setPrototypeOf(this, CacheError.prototype);\n }\n}\n\n/**\n * Error thrown when image processing operations fail.\n *\n * Image processing errors occur during image manipulation, such as:\n * - Image decoding failures\n * - Unsupported image formats\n * - Image resizing/scaling errors\n * - DPI adjustment failures\n * - Color space conversion issues\n *\n * @example\n * ```typescript\n * import { extractFile, ImageProcessingError } from '@kreuzberg/node';\n *\n * try {\n * const result = await extractFile('document.pdf', null, {\n * images: {\n * extractImages: true,\n * targetDpi: 300\n * }\n * });\n * } catch (error) {\n * if (error instanceof ImageProcessingError) {\n * console.error('Image processing failed:', error.message);\n * }\n * }\n * ```\n */\nexport class ImageProcessingError extends KreuzbergError {\n constructor(message: string, panicContext?: PanicContext | null) {\n super(message, panicContext);\n this.name = \"ImageProcessingError\";\n Object.setPrototypeOf(this, ImageProcessingError.prototype);\n }\n}\n\n/**\n * Error thrown when a plugin operation fails.\n *\n * Plugin errors occur in custom plugins (postprocessors, validators, OCR backends), such as:\n * - Plugin initialization failures\n * - Plugin processing errors\n * - Plugin crashes or timeouts\n * - Invalid plugin configuration\n *\n * The error message includes the plugin name to help identify which plugin failed.\n *\n * @example\n * ```typescript\n * import { extractFile, PluginError } from '@kreuzberg/node';\n *\n * try {\n * const result = await extractFile('document.pdf');\n * } catch (error) {\n * if (error instanceof PluginError) {\n * console.error(`Plugin '${error.pluginName}' failed:`, error.message);\n * }\n * }\n * ```\n */\nexport class PluginError extends KreuzbergError {\n /**\n * Name of the plugin that threw the error.\n */\n public readonly pluginName: string;\n\n constructor(message: string, pluginName: string, panicContext?: PanicContext | null) {\n super(`Plugin error in '${pluginName}': ${message}`, panicContext);\n this.name = \"PluginError\";\n this.pluginName = pluginName;\n Object.setPrototypeOf(this, PluginError.prototype);\n }\n\n override toJSON() {\n return {\n name: this.name,\n message: this.message,\n pluginName: this.pluginName,\n panicContext: this.panicContext,\n stack: this.stack,\n };\n }\n}\n\n/**\n * Error thrown when a required system dependency is missing.\n *\n * Missing dependency errors occur when external tools or libraries are not available, such as:\n * - Tesseract OCR (for OCR processing)\n * - ImageMagick (for image processing)\n * - Poppler (for PDF rendering)\n *\n * @example\n * ```typescript\n * import { extractFile, MissingDependencyError } from '@kreuzberg/node';\n *\n * try {\n * const result = await extractFile('document.pdf');\n * } catch (error) {\n * if (error instanceof MissingDependencyError) {\n * console.error('Missing dependency:', error.message);\n * console.log('Please install Tesseract OCR for image processing');\n * }\n * }\n * ```\n */\nexport class MissingDependencyError extends KreuzbergError {\n constructor(message: string, panicContext?: PanicContext | null) {\n super(message, panicContext);\n this.name = \"MissingDependencyError\";\n Object.setPrototypeOf(this, MissingDependencyError.prototype);\n }\n}\n\n/**\n * Error thrown when text embedding generation fails.\n *\n * Embedding errors occur during vector generation, such as:\n * - Model loading failures\n * - Inference engine errors\n * - Invalid input text for the selected model\n * - Resource exhaustion during batch processing\n *\n * @example\n * ```typescript\n * import { embed, EmbeddingError } from '@kreuzberg/node';\n *\n * try {\n * const result = await embed(['hello world']);\n * } catch (error) {\n * if (error instanceof EmbeddingError) {\n * console.error('Embedding generation failed:', error.message);\n * }\n * }\n * ```\n */\nexport class EmbeddingError extends KreuzbergError {\n constructor(message: string, panicContext?: PanicContext | null) {\n super(message, panicContext);\n this.name = \"EmbeddingError\";\n Object.setPrototypeOf(this, EmbeddingError.prototype);\n }\n}\n"],"mappings":";AAyCO,IAAK,YAAL,kBAAKA,eAAL;AAIL,EAAAA,sBAAA,aAAU,KAAV;AAIA,EAAAA,sBAAA,kBAAe,KAAf;AAIA,EAAAA,sBAAA,WAAQ,KAAR;AAIA,EAAAA,sBAAA,qBAAkB,KAAlB;AAIA,EAAAA,sBAAA,aAAU,KAAV;AAIA,EAAAA,sBAAA,kBAAe,KAAf;AAIA,EAAAA,sBAAA,cAAW,KAAX;AAIA,EAAAA,sBAAA,uBAAoB,KAApB;AAIA,EAAAA,sBAAA,eAAY,KAAZ;AApCU,SAAAA;AAAA,GAAA;AA6GL,IAAM,iBAAN,MAAM,wBAAuB,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA,EAKxB;AAA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B,YAAY,SAAiB,YAAoB,cAAoC;AACnF,UAAM,oBAAoB,UAAU,MAAM,OAAO,IAAI,YAAY;AACjE,SAAK,OAAO;AACZ,SAAK,aAAa;AAClB,WAAO,eAAe,MAAM,aAAY,SAAS;AAAA,EACnD;AAAA,EAES,SAAS;AAChB,WAAO;AAAA,MACL,MAAM,KAAK;AAAA,MACX,SAAS,KAAK;AAAA,MACd,YAAY,KAAK;AAAA,MACjB,cAAc,KAAK;AAAA,MACnB,OAAO,KAAK;AAAA,IACd;AAAA,EACF;AACF;AAwBO,IAAM,yBAAN,MAAM,gCAA+B,eAAe;AAAA,EACzD,YAAY,SAAiB,cAAoC;AAC/D,UAAM,SAAS,YAAY;AAC3B,SAAK,OAAO;AACZ,WAAO,eAAe,MAAM,wBAAuB,SAAS;AAAA,EAC9D;AACF;AAwBO,IAAM,iBAAN,MAAM,wBAAuB,eAAe;AAAA,EACjD,YAAY,SAAiB,cAAoC;AAC/D,UAAM,SAAS,YAAY;AAC3B,SAAK,OAAO;AACZ,WAAO,eAAe,MAAM,gBAAe,SAAS;AAAA,EACtD;AACF;","names":["ErrorCode"]}
|
package/dist/index.d.mts
CHANGED
|
@@ -1328,6 +1328,6 @@ declare function __resetBindingForTests(): void;
|
|
|
1328
1328
|
* @module @kreuzberg/node
|
|
1329
1329
|
*/
|
|
1330
1330
|
|
|
1331
|
-
declare const __version__ = "4.
|
|
1331
|
+
declare const __version__ = "4.10.0";
|
|
1332
1332
|
|
|
1333
1333
|
export { EmbeddingConfig, type EmbeddingPreset, ErrorClassification, ExtractionConfig, ExtractionResult, OcrBackendProtocol, PanicContext, PdfPageIterator, type PdfPageResult, PostProcessorProtocol, ValidatorProtocol, WorkerPool, WorkerPoolStats, __resetBindingForTests, __setBindingForTests, __version__, batchExtractBytes, batchExtractBytesSync, batchExtractFiles, batchExtractFilesInWorker, batchExtractFilesSync, classifyError, clearDocumentExtractors, clearOcrBackends, clearPostProcessors, clearValidators, closeWorkerPool, createWorkerPool, detectMimeType, detectMimeTypeFromPath, embed, embedSync, extractBytes, extractBytesSync, extractFile, extractFileInWorker, extractFileSync, getEmbeddingPreset, getErrorCodeDescription, getErrorCodeName, getExtensionsForMime, getLastErrorCode, getLastPanicContext, getWorkerPoolStats, iteratePdfPages, iteratePdfPagesSync, listDocumentExtractors, listEmbeddingPresets, listOcrBackends, listPostProcessors, listValidators, loadConfigFile, loadConfigFromPath, pdfPageCount, registerOcrBackend, registerPostProcessor, registerValidator, renderPdfPage, renderPdfPageSync, unregisterDocumentExtractor, unregisterOcrBackend, unregisterPostProcessor, unregisterValidator, validateMimeType };
|
package/dist/index.d.ts
CHANGED
|
@@ -1328,6 +1328,6 @@ declare function __resetBindingForTests(): void;
|
|
|
1328
1328
|
* @module @kreuzberg/node
|
|
1329
1329
|
*/
|
|
1330
1330
|
|
|
1331
|
-
declare const __version__ = "4.
|
|
1331
|
+
declare const __version__ = "4.10.0";
|
|
1332
1332
|
|
|
1333
1333
|
export { EmbeddingConfig, type EmbeddingPreset, ErrorClassification, ExtractionConfig, ExtractionResult, OcrBackendProtocol, PanicContext, PdfPageIterator, type PdfPageResult, PostProcessorProtocol, ValidatorProtocol, WorkerPool, WorkerPoolStats, __resetBindingForTests, __setBindingForTests, __version__, batchExtractBytes, batchExtractBytesSync, batchExtractFiles, batchExtractFilesInWorker, batchExtractFilesSync, classifyError, clearDocumentExtractors, clearOcrBackends, clearPostProcessors, clearValidators, closeWorkerPool, createWorkerPool, detectMimeType, detectMimeTypeFromPath, embed, embedSync, extractBytes, extractBytesSync, extractFile, extractFileInWorker, extractFileSync, getEmbeddingPreset, getErrorCodeDescription, getErrorCodeName, getExtensionsForMime, getLastErrorCode, getLastPanicContext, getWorkerPoolStats, iteratePdfPages, iteratePdfPagesSync, listDocumentExtractors, listEmbeddingPresets, listOcrBackends, listPostProcessors, listValidators, loadConfigFile, loadConfigFromPath, pdfPageCount, registerOcrBackend, registerPostProcessor, registerValidator, renderPdfPage, renderPdfPageSync, unregisterDocumentExtractor, unregisterOcrBackend, unregisterPostProcessor, unregisterValidator, validateMimeType };
|
package/dist/index.js
CHANGED
|
@@ -1253,7 +1253,7 @@ async function embed(texts, config) {
|
|
|
1253
1253
|
}
|
|
1254
1254
|
|
|
1255
1255
|
// typescript/index.ts
|
|
1256
|
-
var __version__ = "4.
|
|
1256
|
+
var __version__ = "4.10.0";
|
|
1257
1257
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1258
1258
|
0 && (module.exports = {
|
|
1259
1259
|
CacheError,
|