kreuzberg 4.0.0.rc1 → 4.0.0.rc2
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.
- checksums.yaml +4 -4
- data/.gitignore +14 -8
- data/.rspec +3 -3
- data/.rubocop.yaml +1 -534
- data/.rubocop.yml +538 -0
- data/Gemfile +8 -9
- data/Gemfile.lock +9 -109
- data/README.md +426 -421
- data/Rakefile +25 -25
- data/Steepfile +47 -47
- data/examples/async_patterns.rb +341 -340
- data/ext/kreuzberg_rb/extconf.rb +45 -35
- data/ext/kreuzberg_rb/native/Cargo.lock +6535 -0
- data/ext/kreuzberg_rb/native/Cargo.toml +44 -36
- data/ext/kreuzberg_rb/native/README.md +425 -425
- data/ext/kreuzberg_rb/native/build.rs +15 -17
- data/ext/kreuzberg_rb/native/include/ieeefp.h +11 -11
- data/ext/kreuzberg_rb/native/include/msvc_compat/strings.h +14 -14
- data/ext/kreuzberg_rb/native/include/strings.h +20 -20
- data/ext/kreuzberg_rb/native/include/unistd.h +47 -47
- data/ext/kreuzberg_rb/native/src/lib.rs +2998 -2939
- data/extconf.rb +28 -28
- data/kreuzberg.gemspec +148 -105
- data/lib/kreuzberg/api_proxy.rb +142 -142
- data/lib/kreuzberg/cache_api.rb +46 -45
- data/lib/kreuzberg/cli.rb +55 -55
- data/lib/kreuzberg/cli_proxy.rb +127 -127
- data/lib/kreuzberg/config.rb +691 -684
- data/lib/kreuzberg/error_context.rb +32 -0
- data/lib/kreuzberg/errors.rb +118 -50
- data/lib/kreuzberg/extraction_api.rb +85 -84
- data/lib/kreuzberg/mcp_proxy.rb +186 -186
- data/lib/kreuzberg/ocr_backend_protocol.rb +113 -113
- data/lib/kreuzberg/post_processor_protocol.rb +86 -86
- data/lib/kreuzberg/result.rb +216 -216
- data/lib/kreuzberg/setup_lib_path.rb +80 -79
- data/lib/kreuzberg/validator_protocol.rb +89 -89
- data/lib/kreuzberg/version.rb +5 -5
- data/lib/kreuzberg.rb +103 -82
- data/sig/kreuzberg/internal.rbs +184 -184
- data/sig/kreuzberg.rbs +520 -468
- data/spec/binding/cache_spec.rb +227 -227
- data/spec/binding/cli_proxy_spec.rb +85 -87
- data/spec/binding/cli_spec.rb +55 -54
- data/spec/binding/config_spec.rb +345 -345
- data/spec/binding/config_validation_spec.rb +283 -283
- data/spec/binding/error_handling_spec.rb +213 -213
- data/spec/binding/errors_spec.rb +66 -66
- data/spec/binding/plugins/ocr_backend_spec.rb +307 -307
- data/spec/binding/plugins/postprocessor_spec.rb +269 -269
- data/spec/binding/plugins/validator_spec.rb +274 -274
- data/spec/fixtures/config.toml +39 -39
- data/spec/fixtures/config.yaml +41 -42
- data/spec/fixtures/invalid_config.toml +4 -4
- data/spec/smoke/package_spec.rb +178 -178
- data/spec/spec_helper.rb +42 -42
- data/vendor/kreuzberg/Cargo.toml +204 -134
- data/vendor/kreuzberg/README.md +175 -175
- data/vendor/kreuzberg/benches/otel_overhead.rs +48 -0
- data/vendor/kreuzberg/build.rs +474 -460
- data/vendor/kreuzberg/src/api/error.rs +81 -81
- data/vendor/kreuzberg/src/api/handlers.rs +199 -199
- data/vendor/kreuzberg/src/api/mod.rs +79 -79
- data/vendor/kreuzberg/src/api/server.rs +353 -353
- data/vendor/kreuzberg/src/api/types.rs +170 -170
- data/vendor/kreuzberg/src/cache/mod.rs +1167 -1143
- data/vendor/kreuzberg/src/chunking/mod.rs +677 -677
- data/vendor/kreuzberg/src/core/batch_mode.rs +95 -35
- data/vendor/kreuzberg/src/core/config.rs +1032 -1032
- data/vendor/kreuzberg/src/core/extractor.rs +1024 -903
- data/vendor/kreuzberg/src/core/io.rs +329 -327
- data/vendor/kreuzberg/src/core/mime.rs +605 -615
- data/vendor/kreuzberg/src/core/mod.rs +45 -42
- data/vendor/kreuzberg/src/core/pipeline.rs +984 -906
- data/vendor/kreuzberg/src/embeddings.rs +432 -323
- data/vendor/kreuzberg/src/error.rs +431 -431
- data/vendor/kreuzberg/src/extraction/archive.rs +954 -954
- data/vendor/kreuzberg/src/extraction/docx.rs +40 -40
- data/vendor/kreuzberg/src/extraction/email.rs +854 -854
- data/vendor/kreuzberg/src/extraction/excel.rs +688 -688
- data/vendor/kreuzberg/src/extraction/html.rs +553 -553
- data/vendor/kreuzberg/src/extraction/image.rs +368 -368
- data/vendor/kreuzberg/src/extraction/libreoffice.rs +563 -564
- data/vendor/kreuzberg/src/extraction/markdown.rs +213 -0
- data/vendor/kreuzberg/src/extraction/mod.rs +81 -77
- data/vendor/kreuzberg/src/extraction/office_metadata/app_properties.rs +398 -398
- data/vendor/kreuzberg/src/extraction/office_metadata/core_properties.rs +247 -247
- data/vendor/kreuzberg/src/extraction/office_metadata/custom_properties.rs +240 -240
- data/vendor/kreuzberg/src/extraction/office_metadata/mod.rs +130 -128
- data/vendor/kreuzberg/src/extraction/office_metadata/odt_properties.rs +287 -0
- data/vendor/kreuzberg/src/extraction/pptx.rs +3000 -3000
- data/vendor/kreuzberg/src/extraction/structured.rs +490 -490
- data/vendor/kreuzberg/src/extraction/table.rs +328 -328
- data/vendor/kreuzberg/src/extraction/text.rs +269 -269
- data/vendor/kreuzberg/src/extraction/xml.rs +333 -333
- data/vendor/kreuzberg/src/extractors/archive.rs +446 -425
- data/vendor/kreuzberg/src/extractors/bibtex.rs +469 -0
- data/vendor/kreuzberg/src/extractors/docbook.rs +502 -0
- data/vendor/kreuzberg/src/extractors/docx.rs +367 -479
- data/vendor/kreuzberg/src/extractors/email.rs +143 -129
- data/vendor/kreuzberg/src/extractors/epub.rs +707 -0
- data/vendor/kreuzberg/src/extractors/excel.rs +343 -344
- data/vendor/kreuzberg/src/extractors/fictionbook.rs +491 -0
- data/vendor/kreuzberg/src/extractors/fictionbook.rs.backup2 +738 -0
- data/vendor/kreuzberg/src/extractors/html.rs +393 -410
- data/vendor/kreuzberg/src/extractors/image.rs +198 -195
- data/vendor/kreuzberg/src/extractors/jats.rs +1051 -0
- data/vendor/kreuzberg/src/extractors/jupyter.rs +367 -0
- data/vendor/kreuzberg/src/extractors/latex.rs +652 -0
- data/vendor/kreuzberg/src/extractors/markdown.rs +700 -0
- data/vendor/kreuzberg/src/extractors/mod.rs +365 -268
- data/vendor/kreuzberg/src/extractors/odt.rs +628 -0
- data/vendor/kreuzberg/src/extractors/opml.rs +634 -0
- data/vendor/kreuzberg/src/extractors/orgmode.rs +528 -0
- data/vendor/kreuzberg/src/extractors/pdf.rs +493 -496
- data/vendor/kreuzberg/src/extractors/pptx.rs +248 -234
- data/vendor/kreuzberg/src/extractors/rst.rs +576 -0
- data/vendor/kreuzberg/src/extractors/rtf.rs +810 -0
- data/vendor/kreuzberg/src/extractors/security.rs +484 -0
- data/vendor/kreuzberg/src/extractors/security_tests.rs +367 -0
- data/vendor/kreuzberg/src/extractors/structured.rs +140 -126
- data/vendor/kreuzberg/src/extractors/text.rs +260 -242
- data/vendor/kreuzberg/src/extractors/typst.rs +650 -0
- data/vendor/kreuzberg/src/extractors/xml.rs +135 -128
- data/vendor/kreuzberg/src/image/dpi.rs +164 -164
- data/vendor/kreuzberg/src/image/mod.rs +6 -6
- data/vendor/kreuzberg/src/image/preprocessing.rs +417 -417
- data/vendor/kreuzberg/src/image/resize.rs +89 -89
- data/vendor/kreuzberg/src/keywords/config.rs +154 -154
- data/vendor/kreuzberg/src/keywords/mod.rs +237 -237
- data/vendor/kreuzberg/src/keywords/processor.rs +267 -267
- data/vendor/kreuzberg/src/keywords/rake.rs +293 -294
- data/vendor/kreuzberg/src/keywords/types.rs +68 -68
- data/vendor/kreuzberg/src/keywords/yake.rs +163 -163
- data/vendor/kreuzberg/src/language_detection/mod.rs +942 -942
- data/vendor/kreuzberg/src/lib.rs +105 -102
- data/vendor/kreuzberg/src/mcp/mod.rs +32 -32
- data/vendor/kreuzberg/src/mcp/server.rs +1968 -1966
- data/vendor/kreuzberg/src/ocr/cache.rs +469 -469
- data/vendor/kreuzberg/src/ocr/error.rs +37 -37
- data/vendor/kreuzberg/src/ocr/hocr.rs +216 -216
- data/vendor/kreuzberg/src/ocr/mod.rs +58 -58
- data/vendor/kreuzberg/src/ocr/processor.rs +863 -847
- data/vendor/kreuzberg/src/ocr/table/mod.rs +4 -4
- data/vendor/kreuzberg/src/ocr/table/tsv_parser.rs +144 -144
- data/vendor/kreuzberg/src/ocr/tesseract_backend.rs +450 -450
- data/vendor/kreuzberg/src/ocr/types.rs +393 -393
- data/vendor/kreuzberg/src/ocr/utils.rs +47 -47
- data/vendor/kreuzberg/src/ocr/validation.rs +206 -206
- data/vendor/kreuzberg/src/panic_context.rs +154 -0
- data/vendor/kreuzberg/src/pdf/error.rs +122 -122
- data/vendor/kreuzberg/src/pdf/images.rs +139 -139
- data/vendor/kreuzberg/src/pdf/metadata.rs +346 -346
- data/vendor/kreuzberg/src/pdf/mod.rs +50 -50
- data/vendor/kreuzberg/src/pdf/rendering.rs +369 -369
- data/vendor/kreuzberg/src/pdf/table.rs +393 -420
- data/vendor/kreuzberg/src/pdf/text.rs +158 -161
- data/vendor/kreuzberg/src/plugins/extractor.rs +1013 -1010
- data/vendor/kreuzberg/src/plugins/mod.rs +209 -209
- data/vendor/kreuzberg/src/plugins/ocr.rs +620 -629
- data/vendor/kreuzberg/src/plugins/processor.rs +642 -641
- data/vendor/kreuzberg/src/plugins/registry.rs +1337 -1324
- data/vendor/kreuzberg/src/plugins/traits.rs +258 -258
- data/vendor/kreuzberg/src/plugins/validator.rs +956 -955
- data/vendor/kreuzberg/src/stopwords/mod.rs +1470 -1470
- data/vendor/kreuzberg/src/text/mod.rs +19 -19
- data/vendor/kreuzberg/src/text/quality.rs +697 -697
- data/vendor/kreuzberg/src/text/string_utils.rs +217 -217
- data/vendor/kreuzberg/src/text/token_reduction/cjk_utils.rs +164 -164
- data/vendor/kreuzberg/src/text/token_reduction/config.rs +100 -100
- data/vendor/kreuzberg/src/text/token_reduction/core.rs +796 -796
- data/vendor/kreuzberg/src/text/token_reduction/filters.rs +902 -902
- data/vendor/kreuzberg/src/text/token_reduction/mod.rs +160 -160
- data/vendor/kreuzberg/src/text/token_reduction/semantic.rs +619 -619
- data/vendor/kreuzberg/src/text/token_reduction/simd_text.rs +147 -147
- data/vendor/kreuzberg/src/types.rs +903 -873
- data/vendor/kreuzberg/src/utils/mod.rs +17 -17
- data/vendor/kreuzberg/src/utils/quality.rs +959 -959
- data/vendor/kreuzberg/src/utils/string_utils.rs +381 -381
- data/vendor/kreuzberg/stopwords/af_stopwords.json +53 -53
- data/vendor/kreuzberg/stopwords/ar_stopwords.json +482 -482
- data/vendor/kreuzberg/stopwords/bg_stopwords.json +261 -261
- data/vendor/kreuzberg/stopwords/bn_stopwords.json +400 -400
- data/vendor/kreuzberg/stopwords/br_stopwords.json +1205 -1205
- data/vendor/kreuzberg/stopwords/ca_stopwords.json +280 -280
- data/vendor/kreuzberg/stopwords/cs_stopwords.json +425 -425
- data/vendor/kreuzberg/stopwords/da_stopwords.json +172 -172
- data/vendor/kreuzberg/stopwords/de_stopwords.json +622 -622
- data/vendor/kreuzberg/stopwords/el_stopwords.json +849 -849
- data/vendor/kreuzberg/stopwords/en_stopwords.json +1300 -1300
- data/vendor/kreuzberg/stopwords/eo_stopwords.json +175 -175
- data/vendor/kreuzberg/stopwords/es_stopwords.json +734 -734
- data/vendor/kreuzberg/stopwords/et_stopwords.json +37 -37
- data/vendor/kreuzberg/stopwords/eu_stopwords.json +100 -100
- data/vendor/kreuzberg/stopwords/fa_stopwords.json +801 -801
- data/vendor/kreuzberg/stopwords/fi_stopwords.json +849 -849
- data/vendor/kreuzberg/stopwords/fr_stopwords.json +693 -693
- data/vendor/kreuzberg/stopwords/ga_stopwords.json +111 -111
- data/vendor/kreuzberg/stopwords/gl_stopwords.json +162 -162
- data/vendor/kreuzberg/stopwords/gu_stopwords.json +226 -226
- data/vendor/kreuzberg/stopwords/ha_stopwords.json +41 -41
- data/vendor/kreuzberg/stopwords/he_stopwords.json +196 -196
- data/vendor/kreuzberg/stopwords/hi_stopwords.json +227 -227
- data/vendor/kreuzberg/stopwords/hr_stopwords.json +181 -181
- data/vendor/kreuzberg/stopwords/hu_stopwords.json +791 -791
- data/vendor/kreuzberg/stopwords/hy_stopwords.json +47 -47
- data/vendor/kreuzberg/stopwords/id_stopwords.json +760 -760
- data/vendor/kreuzberg/stopwords/it_stopwords.json +634 -634
- data/vendor/kreuzberg/stopwords/ja_stopwords.json +136 -136
- data/vendor/kreuzberg/stopwords/kn_stopwords.json +84 -84
- data/vendor/kreuzberg/stopwords/ko_stopwords.json +681 -681
- data/vendor/kreuzberg/stopwords/ku_stopwords.json +64 -64
- data/vendor/kreuzberg/stopwords/la_stopwords.json +51 -51
- data/vendor/kreuzberg/stopwords/lt_stopwords.json +476 -476
- data/vendor/kreuzberg/stopwords/lv_stopwords.json +163 -163
- data/vendor/kreuzberg/stopwords/ml_stopwords.json +1 -1
- data/vendor/kreuzberg/stopwords/mr_stopwords.json +101 -101
- data/vendor/kreuzberg/stopwords/ms_stopwords.json +477 -477
- data/vendor/kreuzberg/stopwords/ne_stopwords.json +490 -490
- data/vendor/kreuzberg/stopwords/nl_stopwords.json +415 -415
- data/vendor/kreuzberg/stopwords/no_stopwords.json +223 -223
- data/vendor/kreuzberg/stopwords/pl_stopwords.json +331 -331
- data/vendor/kreuzberg/stopwords/pt_stopwords.json +562 -562
- data/vendor/kreuzberg/stopwords/ro_stopwords.json +436 -436
- data/vendor/kreuzberg/stopwords/ru_stopwords.json +561 -561
- data/vendor/kreuzberg/stopwords/si_stopwords.json +193 -193
- data/vendor/kreuzberg/stopwords/sk_stopwords.json +420 -420
- data/vendor/kreuzberg/stopwords/sl_stopwords.json +448 -448
- data/vendor/kreuzberg/stopwords/so_stopwords.json +32 -32
- data/vendor/kreuzberg/stopwords/st_stopwords.json +33 -33
- data/vendor/kreuzberg/stopwords/sv_stopwords.json +420 -420
- data/vendor/kreuzberg/stopwords/sw_stopwords.json +76 -76
- data/vendor/kreuzberg/stopwords/ta_stopwords.json +129 -129
- data/vendor/kreuzberg/stopwords/te_stopwords.json +54 -54
- data/vendor/kreuzberg/stopwords/th_stopwords.json +118 -118
- data/vendor/kreuzberg/stopwords/tl_stopwords.json +149 -149
- data/vendor/kreuzberg/stopwords/tr_stopwords.json +506 -506
- data/vendor/kreuzberg/stopwords/uk_stopwords.json +75 -75
- data/vendor/kreuzberg/stopwords/ur_stopwords.json +519 -519
- data/vendor/kreuzberg/stopwords/vi_stopwords.json +647 -647
- data/vendor/kreuzberg/stopwords/yo_stopwords.json +62 -62
- data/vendor/kreuzberg/stopwords/zh_stopwords.json +796 -796
- data/vendor/kreuzberg/stopwords/zu_stopwords.json +31 -31
- data/vendor/kreuzberg/tests/api_extract_multipart.rs +52 -0
- data/vendor/kreuzberg/tests/api_tests.rs +966 -966
- data/vendor/kreuzberg/tests/archive_integration.rs +543 -543
- data/vendor/kreuzberg/tests/batch_orchestration.rs +556 -542
- data/vendor/kreuzberg/tests/batch_processing.rs +316 -304
- data/vendor/kreuzberg/tests/bibtex_parity_test.rs +421 -0
- data/vendor/kreuzberg/tests/concurrency_stress.rs +525 -509
- data/vendor/kreuzberg/tests/config_features.rs +598 -580
- data/vendor/kreuzberg/tests/config_loading_tests.rs +415 -439
- data/vendor/kreuzberg/tests/core_integration.rs +510 -493
- data/vendor/kreuzberg/tests/csv_integration.rs +414 -424
- data/vendor/kreuzberg/tests/docbook_extractor_tests.rs +498 -0
- data/vendor/kreuzberg/tests/docx_metadata_extraction_test.rs +122 -124
- data/vendor/kreuzberg/tests/docx_vs_pandoc_comparison.rs +370 -0
- data/vendor/kreuzberg/tests/email_integration.rs +325 -325
- data/vendor/kreuzberg/tests/epub_native_extractor_tests.rs +275 -0
- data/vendor/kreuzberg/tests/error_handling.rs +393 -393
- data/vendor/kreuzberg/tests/fictionbook_extractor_tests.rs +228 -0
- data/vendor/kreuzberg/tests/format_integration.rs +159 -159
- data/vendor/kreuzberg/tests/helpers/mod.rs +142 -142
- data/vendor/kreuzberg/tests/html_table_test.rs +551 -0
- data/vendor/kreuzberg/tests/image_integration.rs +253 -253
- data/vendor/kreuzberg/tests/instrumentation_test.rs +139 -0
- data/vendor/kreuzberg/tests/jats_extractor_tests.rs +639 -0
- data/vendor/kreuzberg/tests/jupyter_extractor_tests.rs +704 -0
- data/vendor/kreuzberg/tests/keywords_integration.rs +479 -479
- data/vendor/kreuzberg/tests/keywords_quality.rs +509 -509
- data/vendor/kreuzberg/tests/latex_extractor_tests.rs +496 -0
- data/vendor/kreuzberg/tests/markdown_extractor_tests.rs +490 -0
- data/vendor/kreuzberg/tests/mime_detection.rs +428 -428
- data/vendor/kreuzberg/tests/ocr_configuration.rs +510 -510
- data/vendor/kreuzberg/tests/ocr_errors.rs +676 -676
- data/vendor/kreuzberg/tests/ocr_quality.rs +627 -627
- data/vendor/kreuzberg/tests/ocr_stress.rs +469 -469
- data/vendor/kreuzberg/tests/odt_extractor_tests.rs +695 -0
- data/vendor/kreuzberg/tests/opml_extractor_tests.rs +616 -0
- data/vendor/kreuzberg/tests/orgmode_extractor_tests.rs +822 -0
- data/vendor/kreuzberg/tests/pdf_integration.rs +43 -43
- data/vendor/kreuzberg/tests/pipeline_integration.rs +1411 -1412
- data/vendor/kreuzberg/tests/plugin_ocr_backend_test.rs +771 -771
- data/vendor/kreuzberg/tests/plugin_postprocessor_test.rs +560 -561
- data/vendor/kreuzberg/tests/plugin_system.rs +921 -921
- data/vendor/kreuzberg/tests/plugin_validator_test.rs +783 -783
- data/vendor/kreuzberg/tests/registry_integration_tests.rs +586 -607
- data/vendor/kreuzberg/tests/rst_extractor_tests.rs +692 -0
- data/vendor/kreuzberg/tests/rtf_extractor_tests.rs +776 -0
- data/vendor/kreuzberg/tests/security_validation.rs +415 -404
- data/vendor/kreuzberg/tests/stopwords_integration_test.rs +888 -888
- data/vendor/kreuzberg/tests/test_fastembed.rs +609 -609
- data/vendor/kreuzberg/tests/typst_behavioral_tests.rs +1259 -0
- data/vendor/kreuzberg/tests/typst_extractor_tests.rs +647 -0
- data/vendor/kreuzberg/tests/xlsx_metadata_extraction_test.rs +87 -87
- data/vendor/rb-sys/.cargo-ok +1 -0
- data/vendor/rb-sys/.cargo_vcs_info.json +6 -0
- data/vendor/rb-sys/Cargo.lock +393 -0
- data/vendor/rb-sys/Cargo.toml +70 -0
- data/vendor/rb-sys/Cargo.toml.orig +57 -0
- data/vendor/rb-sys/LICENSE-APACHE +190 -0
- data/vendor/rb-sys/LICENSE-MIT +21 -0
- data/vendor/rb-sys/bin/release.sh +21 -0
- data/vendor/rb-sys/build/features.rs +108 -0
- data/vendor/rb-sys/build/main.rs +246 -0
- data/vendor/rb-sys/build/stable_api_config.rs +153 -0
- data/vendor/rb-sys/build/version.rs +48 -0
- data/vendor/rb-sys/readme.md +36 -0
- data/vendor/rb-sys/src/bindings.rs +21 -0
- data/vendor/rb-sys/src/hidden.rs +11 -0
- data/vendor/rb-sys/src/lib.rs +34 -0
- data/vendor/rb-sys/src/macros.rs +371 -0
- data/vendor/rb-sys/src/memory.rs +53 -0
- data/vendor/rb-sys/src/ruby_abi_version.rs +38 -0
- data/vendor/rb-sys/src/special_consts.rs +31 -0
- data/vendor/rb-sys/src/stable_api/compiled.c +179 -0
- data/vendor/rb-sys/src/stable_api/compiled.rs +257 -0
- data/vendor/rb-sys/src/stable_api/ruby_2_6.rs +316 -0
- data/vendor/rb-sys/src/stable_api/ruby_2_7.rs +316 -0
- data/vendor/rb-sys/src/stable_api/ruby_3_0.rs +324 -0
- data/vendor/rb-sys/src/stable_api/ruby_3_1.rs +317 -0
- data/vendor/rb-sys/src/stable_api/ruby_3_2.rs +315 -0
- data/vendor/rb-sys/src/stable_api/ruby_3_3.rs +326 -0
- data/vendor/rb-sys/src/stable_api/ruby_3_4.rs +327 -0
- data/vendor/rb-sys/src/stable_api.rs +261 -0
- data/vendor/rb-sys/src/symbol.rs +31 -0
- data/vendor/rb-sys/src/tracking_allocator.rs +332 -0
- data/vendor/rb-sys/src/utils.rs +89 -0
- data/vendor/rb-sys/src/value_type.rs +7 -0
- metadata +90 -95
- data/pkg/kreuzberg-4.0.0.rc1.gem +0 -0
- data/spec/examples.txt +0 -104
- data/vendor/kreuzberg/src/bin/profile_extract.rs +0 -455
- data/vendor/kreuzberg/src/extraction/pandoc/batch.rs +0 -275
- data/vendor/kreuzberg/src/extraction/pandoc/mime_types.rs +0 -178
- data/vendor/kreuzberg/src/extraction/pandoc/mod.rs +0 -491
- data/vendor/kreuzberg/src/extraction/pandoc/server.rs +0 -496
- data/vendor/kreuzberg/src/extraction/pandoc/subprocess.rs +0 -1188
- data/vendor/kreuzberg/src/extraction/pandoc/version.rs +0 -162
- data/vendor/kreuzberg/src/extractors/pandoc.rs +0 -201
- data/vendor/kreuzberg/tests/chunking_offset_demo.rs +0 -92
- data/vendor/kreuzberg/tests/pandoc_integration.rs +0 -503
data/extconf.rb
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'mkmf'
|
|
4
|
-
require 'rb_sys/mkmf'
|
|
5
|
-
require 'rbconfig'
|
|
6
|
-
|
|
7
|
-
if /mswin|mingw/.match?(RbConfig::CONFIG['host_os'])
|
|
8
|
-
devkit = ENV.fetch('RI_DEVKIT', nil)
|
|
9
|
-
prefix = ENV['MSYSTEM_PREFIX'] || '/ucrt64'
|
|
10
|
-
|
|
11
|
-
if devkit
|
|
12
|
-
sysroot = "#{devkit}#{prefix}".tr('\\\\', '/')
|
|
13
|
-
extra_args = [
|
|
14
|
-
'--target=x86_64-pc-windows-gnu',
|
|
15
|
-
"--sysroot=#{sysroot}"
|
|
16
|
-
]
|
|
17
|
-
|
|
18
|
-
existing = ENV['BINDGEN_EXTRA_CLANG_ARGS'].to_s.split(/\s+/)
|
|
19
|
-
ENV['BINDGEN_EXTRA_CLANG_ARGS'] = (existing + extra_args).uniq.join(' ')
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
default_profile = ENV.fetch('CARGO_PROFILE', 'release')
|
|
24
|
-
|
|
25
|
-
create_rust_makefile('kreuzberg_rb') do |config|
|
|
26
|
-
config.profile = default_profile.to_sym
|
|
27
|
-
config.ext_dir = File.expand_path('ext/kreuzberg_rb/native', __dir__)
|
|
28
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'mkmf'
|
|
4
|
+
require 'rb_sys/mkmf'
|
|
5
|
+
require 'rbconfig'
|
|
6
|
+
|
|
7
|
+
if /mswin|mingw/.match?(RbConfig::CONFIG['host_os'])
|
|
8
|
+
devkit = ENV.fetch('RI_DEVKIT', nil)
|
|
9
|
+
prefix = ENV['MSYSTEM_PREFIX'] || '/ucrt64'
|
|
10
|
+
|
|
11
|
+
if devkit
|
|
12
|
+
sysroot = "#{devkit}#{prefix}".tr('\\\\', '/')
|
|
13
|
+
extra_args = [
|
|
14
|
+
'--target=x86_64-pc-windows-gnu',
|
|
15
|
+
"--sysroot=#{sysroot}"
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
existing = ENV['BINDGEN_EXTRA_CLANG_ARGS'].to_s.split(/\s+/)
|
|
19
|
+
ENV['BINDGEN_EXTRA_CLANG_ARGS'] = (existing + extra_args).uniq.join(' ')
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
default_profile = ENV.fetch('CARGO_PROFILE', 'release')
|
|
24
|
+
|
|
25
|
+
create_rust_makefile('kreuzberg_rb') do |config|
|
|
26
|
+
config.profile = default_profile.to_sym
|
|
27
|
+
config.ext_dir = File.expand_path('ext/kreuzberg_rb/native', __dir__)
|
|
28
|
+
end
|
data/kreuzberg.gemspec
CHANGED
|
@@ -1,105 +1,148 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative 'lib/kreuzberg/version'
|
|
4
|
-
|
|
5
|
-
repo_root = File.expand_path('../..', __dir__)
|
|
6
|
-
|
|
7
|
-
# Include files from packages/ruby
|
|
8
|
-
ruby_prefix = 'packages/ruby/'
|
|
9
|
-
ruby_cmd = %(git -C "#{repo_root}" ls-files -z #{ruby_prefix})
|
|
10
|
-
ruby_files =
|
|
11
|
-
`#{ruby_cmd}`.split("\x0")
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
# Include the kreuzberg core crate (needed for path patch in Cargo.toml)
|
|
16
|
-
core_prefix = 'crates/kreuzberg/'
|
|
17
|
-
core_cmd = %(git -C "#{repo_root}" ls-files -z #{core_prefix})
|
|
18
|
-
core_files =
|
|
19
|
-
`#{core_cmd}`.split("\x0")
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
fallback_files = Dir.chdir(__dir__) do
|
|
25
|
-
ruby_fallback = Dir.glob(
|
|
26
|
-
%w[
|
|
27
|
-
README.md
|
|
28
|
-
LICENSE
|
|
29
|
-
ext/**/*.rs
|
|
30
|
-
ext/**/*.rb
|
|
31
|
-
ext/**/*.toml
|
|
32
|
-
ext/**/*.lock
|
|
33
|
-
ext/**/*.md
|
|
34
|
-
ext/**/build.rs
|
|
35
|
-
ext/**/Cargo.*
|
|
36
|
-
exe/*
|
|
37
|
-
lib/**/*.rb
|
|
38
|
-
sig/**/*.rbs
|
|
39
|
-
spec/**/*.rb
|
|
40
|
-
],
|
|
41
|
-
File::FNM_DOTMATCH
|
|
42
|
-
)
|
|
43
|
-
|
|
44
|
-
# Fallback for core crate - copy from repo root
|
|
45
|
-
core_fallback = Dir.chdir(repo_root) do
|
|
46
|
-
Dir.glob('crates/kreuzberg/**/*', File::FNM_DOTMATCH)
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
ruby_fallback + core_fallback
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'lib/kreuzberg/version'
|
|
4
|
+
|
|
5
|
+
repo_root = File.expand_path('../..', __dir__)
|
|
6
|
+
|
|
7
|
+
# Include files from packages/ruby
|
|
8
|
+
ruby_prefix = 'packages/ruby/'
|
|
9
|
+
ruby_cmd = %(git -C "#{repo_root}" ls-files -z #{ruby_prefix})
|
|
10
|
+
ruby_files =
|
|
11
|
+
`#{ruby_cmd}`.split("\x0")
|
|
12
|
+
.select { |path| path.start_with?(ruby_prefix) }
|
|
13
|
+
.map { |path| path.delete_prefix(ruby_prefix) }
|
|
14
|
+
|
|
15
|
+
# Include the kreuzberg core crate (needed for path patch in Cargo.toml)
|
|
16
|
+
core_prefix = 'crates/kreuzberg/'
|
|
17
|
+
core_cmd = %(git -C "#{repo_root}" ls-files -z #{core_prefix})
|
|
18
|
+
core_files =
|
|
19
|
+
`#{core_cmd}`.split("\x0")
|
|
20
|
+
.select { |path| path.start_with?(core_prefix) }
|
|
21
|
+
.map { |path| path.delete_prefix('crates/') }
|
|
22
|
+
.map { |path| "vendor/#{path}" }
|
|
23
|
+
|
|
24
|
+
fallback_files = Dir.chdir(__dir__) do
|
|
25
|
+
ruby_fallback = Dir.glob(
|
|
26
|
+
%w[
|
|
27
|
+
README.md
|
|
28
|
+
LICENSE
|
|
29
|
+
ext/**/*.rs
|
|
30
|
+
ext/**/*.rb
|
|
31
|
+
ext/**/*.toml
|
|
32
|
+
ext/**/*.lock
|
|
33
|
+
ext/**/*.md
|
|
34
|
+
ext/**/build.rs
|
|
35
|
+
ext/**/Cargo.*
|
|
36
|
+
exe/*
|
|
37
|
+
lib/**/*.rb
|
|
38
|
+
sig/**/*.rbs
|
|
39
|
+
spec/**/*.rb
|
|
40
|
+
],
|
|
41
|
+
File::FNM_DOTMATCH
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
# Fallback for core crate - copy from repo root
|
|
45
|
+
core_fallback = Dir.chdir(repo_root) do
|
|
46
|
+
Dir.glob('crates/kreuzberg/**/*', File::FNM_DOTMATCH)
|
|
47
|
+
.reject { |f| File.directory?(f) }
|
|
48
|
+
.map { |path| "vendor/#{path.delete_prefix('crates/')}" }
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
ruby_fallback + core_fallback
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Check for vendored crates (copied during CI/packaging)
|
|
55
|
+
vendor_files = Dir.chdir(__dir__) do
|
|
56
|
+
kreuzberg_files = if Dir.exist?('vendor/kreuzberg')
|
|
57
|
+
Dir.glob('vendor/kreuzberg/**/*', File::FNM_DOTMATCH)
|
|
58
|
+
.reject { |f| File.directory?(f) }
|
|
59
|
+
.reject { |f| f.include?('/.fastembed_cache/') }
|
|
60
|
+
.reject { |f| f.include?('/target/') }
|
|
61
|
+
.grep_v(/\.(swp|bak|tmp)$/)
|
|
62
|
+
.grep_v(/~$/)
|
|
63
|
+
else
|
|
64
|
+
[]
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
rb_sys_files = if Dir.exist?('vendor/rb-sys')
|
|
68
|
+
Dir.glob('vendor/rb-sys/**/*', File::FNM_DOTMATCH)
|
|
69
|
+
.reject { |f| File.directory?(f) }
|
|
70
|
+
.reject { |f| f.include?('/target/') }
|
|
71
|
+
.grep_v(/\.(swp|bak|tmp)$/)
|
|
72
|
+
.grep_v(/~$/)
|
|
73
|
+
else
|
|
74
|
+
[]
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
workspace_toml = if File.exist?('vendor/Cargo.toml')
|
|
78
|
+
['vendor/Cargo.toml']
|
|
79
|
+
else
|
|
80
|
+
[]
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
kreuzberg_files + rb_sys_files + workspace_toml
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# Use git-tracked files if available, otherwise fallback to glob
|
|
87
|
+
# Always include vendored files if they exist on disk (for CI packaging)
|
|
88
|
+
files = if (ruby_files + core_files).empty?
|
|
89
|
+
fallback_files
|
|
90
|
+
elsif vendor_files.any?
|
|
91
|
+
ruby_files + vendor_files
|
|
92
|
+
else
|
|
93
|
+
ruby_files + core_files
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# Filter to only include files that actually exist
|
|
97
|
+
files = files.select { |f| File.exist?(f) }
|
|
98
|
+
|
|
99
|
+
Gem::Specification.new do |spec|
|
|
100
|
+
spec.name = 'kreuzberg'
|
|
101
|
+
spec.version = Kreuzberg::VERSION
|
|
102
|
+
spec.authors = ['Na\'aman Hirschfeld']
|
|
103
|
+
spec.email = ['nhirschfeld@gmail.com']
|
|
104
|
+
|
|
105
|
+
spec.summary = 'High-performance document intelligence framework'
|
|
106
|
+
spec.description = <<~DESC
|
|
107
|
+
Kreuzberg is a multi-language document intelligence framework with a high-performance
|
|
108
|
+
Rust core. Supports extraction, OCR, chunking, and language detection for 30+ file formats
|
|
109
|
+
including PDF, DOCX, PPTX, XLSX, images, and more.
|
|
110
|
+
DESC
|
|
111
|
+
spec.homepage = 'https://github.com/kreuzberg-dev/kreuzberg'
|
|
112
|
+
spec.license = 'MIT'
|
|
113
|
+
spec.required_ruby_version = '>= 3.2.0'
|
|
114
|
+
|
|
115
|
+
spec.metadata = {
|
|
116
|
+
'homepage_uri' => spec.homepage,
|
|
117
|
+
'source_code_uri' => 'https://github.com/kreuzberg-dev/kreuzberg',
|
|
118
|
+
'changelog_uri' => 'https://github.com/kreuzberg-dev/kreuzberg/blob/main/CHANGELOG.md',
|
|
119
|
+
'documentation_uri' => 'https://docs.kreuzberg.dev',
|
|
120
|
+
'bug_tracker_uri' => 'https://github.com/kreuzberg-dev/kreuzberg/issues',
|
|
121
|
+
'rubygems_mfa_required' => 'true',
|
|
122
|
+
'keywords' => 'document-intelligence,document-extraction,ocr,rust,bindings'
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
spec.files = files
|
|
126
|
+
spec.bindir = 'exe'
|
|
127
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
128
|
+
spec.require_paths = ['lib']
|
|
129
|
+
spec.extensions = ['ext/kreuzberg_rb/extconf.rb']
|
|
130
|
+
|
|
131
|
+
# Runtime dependencies
|
|
132
|
+
# None - the gem is self-contained with the Rust extension
|
|
133
|
+
|
|
134
|
+
# Development dependencies
|
|
135
|
+
spec.add_development_dependency 'bundler', '~> 4.0'
|
|
136
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
|
137
|
+
spec.add_development_dependency 'rake-compiler', '~> 1.2'
|
|
138
|
+
spec.add_development_dependency 'rb_sys', '~> 0.9.119'
|
|
139
|
+
spec.add_development_dependency 'rspec', '~> 3.12'
|
|
140
|
+
unless Gem.win_platform?
|
|
141
|
+
spec.add_development_dependency 'rbs', '~> 3.0'
|
|
142
|
+
spec.add_development_dependency 'rubocop', '~> 1.66'
|
|
143
|
+
spec.add_development_dependency 'rubocop-performance', '~> 1.21'
|
|
144
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 3.0'
|
|
145
|
+
spec.add_development_dependency 'steep', '~> 1.8'
|
|
146
|
+
end
|
|
147
|
+
spec.add_development_dependency 'yard', '~> 0.9'
|
|
148
|
+
end
|
data/lib/kreuzberg/api_proxy.rb
CHANGED
|
@@ -1,142 +1,142 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'open3'
|
|
4
|
-
require 'pathname'
|
|
5
|
-
|
|
6
|
-
module Kreuzberg
|
|
7
|
-
# API server proxy
|
|
8
|
-
#
|
|
9
|
-
# Starts and manages the Kreuzberg API server (Litestar/Python-based or Rust-based).
|
|
10
|
-
#
|
|
11
|
-
# @example Start the server
|
|
12
|
-
# server = Kreuzberg::APIProxy.new(port: 8000)
|
|
13
|
-
# server.start
|
|
14
|
-
# # Server runs in background
|
|
15
|
-
# server.stop
|
|
16
|
-
#
|
|
17
|
-
# @example With block
|
|
18
|
-
# Kreuzberg::APIProxy.run(port: 8000) do |server|
|
|
19
|
-
# # Server runs while block executes
|
|
20
|
-
# response = Net::HTTP.get(URI('http://localhost:8000/health'))
|
|
21
|
-
# end
|
|
22
|
-
#
|
|
23
|
-
module APIProxy
|
|
24
|
-
Error = Class.new(Kreuzberg::Errors::Error)
|
|
25
|
-
MissingBinaryError = Class.new(Error)
|
|
26
|
-
ServerError = Class.new(Error)
|
|
27
|
-
|
|
28
|
-
# API server instance
|
|
29
|
-
class Server
|
|
30
|
-
attr_reader :port, :host, :pid
|
|
31
|
-
|
|
32
|
-
# Initialize server
|
|
33
|
-
#
|
|
34
|
-
# @param port [Integer] Port to run on (default: 8000)
|
|
35
|
-
# @param host [String] Host to bind to (default: "0.0.0.0")
|
|
36
|
-
#
|
|
37
|
-
def initialize(port: 8000, host: '0.0.0.0')
|
|
38
|
-
@port = port
|
|
39
|
-
@host = host
|
|
40
|
-
@pid = nil
|
|
41
|
-
@process = nil
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
# Start the server in the background
|
|
45
|
-
#
|
|
46
|
-
# @return [Integer] Process ID
|
|
47
|
-
# @raise [ServerError] If server fails to start
|
|
48
|
-
#
|
|
49
|
-
def start
|
|
50
|
-
binary = APIProxy.find_api_binary
|
|
51
|
-
@pid = spawn(
|
|
52
|
-
binary.to_s,
|
|
53
|
-
'api',
|
|
54
|
-
'--host', @host,
|
|
55
|
-
'--port', @port.to_s,
|
|
56
|
-
out: $stdout,
|
|
57
|
-
err: $stderr
|
|
58
|
-
)
|
|
59
|
-
Process.detach(@pid)
|
|
60
|
-
sleep 1 # Give server time to start
|
|
61
|
-
@pid
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
# Stop the server
|
|
65
|
-
#
|
|
66
|
-
# @return [void]
|
|
67
|
-
#
|
|
68
|
-
def stop
|
|
69
|
-
return unless @pid
|
|
70
|
-
|
|
71
|
-
Process.kill('TERM', @pid)
|
|
72
|
-
Process.wait(@pid)
|
|
73
|
-
rescue Errno::ESRCH, Errno::ECHILD
|
|
74
|
-
# Process already dead
|
|
75
|
-
ensure
|
|
76
|
-
@pid = nil
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
# Check if server is running
|
|
80
|
-
#
|
|
81
|
-
# @return [Boolean]
|
|
82
|
-
#
|
|
83
|
-
def running?
|
|
84
|
-
return false unless @pid
|
|
85
|
-
|
|
86
|
-
Process.kill(0, @pid)
|
|
87
|
-
true
|
|
88
|
-
rescue Errno::ESRCH, Errno::EPERM
|
|
89
|
-
false
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
module_function
|
|
94
|
-
|
|
95
|
-
# Run server with a block
|
|
96
|
-
#
|
|
97
|
-
# @param port [Integer] Port to run on
|
|
98
|
-
# @param host [String] Host to bind to
|
|
99
|
-
# @yield [Server] Yields server instance
|
|
100
|
-
# @return [Object] Block result
|
|
101
|
-
#
|
|
102
|
-
# @example
|
|
103
|
-
# Kreuzberg::APIProxy.run(port: 8000) do |server|
|
|
104
|
-
# # Make API requests
|
|
105
|
-
# end
|
|
106
|
-
#
|
|
107
|
-
def run(port: 8000, host: '0.0.0.0')
|
|
108
|
-
server = Server.new(port: port, host: host)
|
|
109
|
-
server.start
|
|
110
|
-
yield server
|
|
111
|
-
ensure
|
|
112
|
-
server&.stop
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
# Find the API binary
|
|
116
|
-
#
|
|
117
|
-
# @return [Pathname] Path to binary
|
|
118
|
-
# @raise [MissingBinaryError] If not found
|
|
119
|
-
#
|
|
120
|
-
def find_api_binary
|
|
121
|
-
# API might be served by kreuzberg CLI or a separate binary
|
|
122
|
-
binary_name = Gem.win_platform? ? 'kreuzberg.exe' : 'kreuzberg'
|
|
123
|
-
found = CLIProxy.search_paths(binary_name).find(&:file?)
|
|
124
|
-
return found if found
|
|
125
|
-
|
|
126
|
-
raise MissingBinaryError, missing_binary_message
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
# Error message for missing binary
|
|
130
|
-
#
|
|
131
|
-
# @return [String]
|
|
132
|
-
#
|
|
133
|
-
def missing_binary_message
|
|
134
|
-
<<~MSG.strip
|
|
135
|
-
kreuzberg binary not found for API server. Build it with:
|
|
136
|
-
`cargo build --release --package kreuzberg-cli`
|
|
137
|
-
|
|
138
|
-
Or ensure kreuzberg is installed with API support.
|
|
139
|
-
MSG
|
|
140
|
-
end
|
|
141
|
-
end
|
|
142
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'open3'
|
|
4
|
+
require 'pathname'
|
|
5
|
+
|
|
6
|
+
module Kreuzberg
|
|
7
|
+
# API server proxy
|
|
8
|
+
#
|
|
9
|
+
# Starts and manages the Kreuzberg API server (Litestar/Python-based or Rust-based).
|
|
10
|
+
#
|
|
11
|
+
# @example Start the server
|
|
12
|
+
# server = Kreuzberg::APIProxy.new(port: 8000)
|
|
13
|
+
# server.start
|
|
14
|
+
# # Server runs in background
|
|
15
|
+
# server.stop
|
|
16
|
+
#
|
|
17
|
+
# @example With block
|
|
18
|
+
# Kreuzberg::APIProxy.run(port: 8000) do |server|
|
|
19
|
+
# # Server runs while block executes
|
|
20
|
+
# response = Net::HTTP.get(URI('http://localhost:8000/health'))
|
|
21
|
+
# end
|
|
22
|
+
#
|
|
23
|
+
module APIProxy
|
|
24
|
+
Error = Class.new(Kreuzberg::Errors::Error)
|
|
25
|
+
MissingBinaryError = Class.new(Error)
|
|
26
|
+
ServerError = Class.new(Error)
|
|
27
|
+
|
|
28
|
+
# API server instance
|
|
29
|
+
class Server
|
|
30
|
+
attr_reader :port, :host, :pid
|
|
31
|
+
|
|
32
|
+
# Initialize server
|
|
33
|
+
#
|
|
34
|
+
# @param port [Integer] Port to run on (default: 8000)
|
|
35
|
+
# @param host [String] Host to bind to (default: "0.0.0.0")
|
|
36
|
+
#
|
|
37
|
+
def initialize(port: 8000, host: '0.0.0.0')
|
|
38
|
+
@port = port
|
|
39
|
+
@host = host
|
|
40
|
+
@pid = nil
|
|
41
|
+
@process = nil
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Start the server in the background
|
|
45
|
+
#
|
|
46
|
+
# @return [Integer] Process ID
|
|
47
|
+
# @raise [ServerError] If server fails to start
|
|
48
|
+
#
|
|
49
|
+
def start
|
|
50
|
+
binary = APIProxy.find_api_binary
|
|
51
|
+
@pid = spawn(
|
|
52
|
+
binary.to_s,
|
|
53
|
+
'api',
|
|
54
|
+
'--host', @host,
|
|
55
|
+
'--port', @port.to_s,
|
|
56
|
+
out: $stdout,
|
|
57
|
+
err: $stderr
|
|
58
|
+
)
|
|
59
|
+
Process.detach(@pid)
|
|
60
|
+
sleep 1 # Give server time to start
|
|
61
|
+
@pid
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Stop the server
|
|
65
|
+
#
|
|
66
|
+
# @return [void]
|
|
67
|
+
#
|
|
68
|
+
def stop
|
|
69
|
+
return unless @pid
|
|
70
|
+
|
|
71
|
+
Process.kill('TERM', @pid)
|
|
72
|
+
Process.wait(@pid)
|
|
73
|
+
rescue Errno::ESRCH, Errno::ECHILD
|
|
74
|
+
# Process already dead
|
|
75
|
+
ensure
|
|
76
|
+
@pid = nil
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# Check if server is running
|
|
80
|
+
#
|
|
81
|
+
# @return [Boolean]
|
|
82
|
+
#
|
|
83
|
+
def running?
|
|
84
|
+
return false unless @pid
|
|
85
|
+
|
|
86
|
+
Process.kill(0, @pid)
|
|
87
|
+
true
|
|
88
|
+
rescue Errno::ESRCH, Errno::EPERM
|
|
89
|
+
false
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
module_function
|
|
94
|
+
|
|
95
|
+
# Run server with a block
|
|
96
|
+
#
|
|
97
|
+
# @param port [Integer] Port to run on
|
|
98
|
+
# @param host [String] Host to bind to
|
|
99
|
+
# @yield [Server] Yields server instance
|
|
100
|
+
# @return [Object] Block result
|
|
101
|
+
#
|
|
102
|
+
# @example
|
|
103
|
+
# Kreuzberg::APIProxy.run(port: 8000) do |server|
|
|
104
|
+
# # Make API requests
|
|
105
|
+
# end
|
|
106
|
+
#
|
|
107
|
+
def run(port: 8000, host: '0.0.0.0')
|
|
108
|
+
server = Server.new(port: port, host: host)
|
|
109
|
+
server.start
|
|
110
|
+
yield server
|
|
111
|
+
ensure
|
|
112
|
+
server&.stop
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# Find the API binary
|
|
116
|
+
#
|
|
117
|
+
# @return [Pathname] Path to binary
|
|
118
|
+
# @raise [MissingBinaryError] If not found
|
|
119
|
+
#
|
|
120
|
+
def find_api_binary
|
|
121
|
+
# API might be served by kreuzberg CLI or a separate binary
|
|
122
|
+
binary_name = Gem.win_platform? ? 'kreuzberg.exe' : 'kreuzberg'
|
|
123
|
+
found = CLIProxy.search_paths(binary_name).find(&:file?)
|
|
124
|
+
return found if found
|
|
125
|
+
|
|
126
|
+
raise MissingBinaryError, missing_binary_message
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
# Error message for missing binary
|
|
130
|
+
#
|
|
131
|
+
# @return [String]
|
|
132
|
+
#
|
|
133
|
+
def missing_binary_message
|
|
134
|
+
<<~MSG.strip
|
|
135
|
+
kreuzberg binary not found for API server. Build it with:
|
|
136
|
+
`cargo build --release --package kreuzberg-cli`
|
|
137
|
+
|
|
138
|
+
Or ensure kreuzberg is installed with API support.
|
|
139
|
+
MSG
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
end
|