703 lines
28 KiB
Java
Generated
703 lines
28 KiB
Java
Generated
// This file is auto-generated by alef — DO NOT EDIT.
|
|
// alef:hash:4e15143f4af1ae8bafbdb1506ef057da924484c66a19483966333558ad437e75
|
|
// To regenerate: alef generate
|
|
// To verify freshness: alef verify --exit-code
|
|
// Issues & docs: https://github.com/kreuzberg-dev/alef
|
|
package dev.kreuzberg;
|
|
|
|
import java.lang.foreign.Arena;
|
|
import java.lang.foreign.FunctionDescriptor;
|
|
import java.lang.foreign.Linker;
|
|
import java.lang.foreign.MemoryLayout;
|
|
import java.lang.foreign.SymbolLookup;
|
|
import java.lang.foreign.ValueLayout;
|
|
import java.lang.invoke.MethodHandle;
|
|
import java.io.File;
|
|
import java.net.URL;
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Path;
|
|
import java.nio.file.Paths;
|
|
import java.nio.file.StandardCopyOption;
|
|
import java.util.ArrayList;
|
|
import java.util.Enumeration;
|
|
import java.util.List;
|
|
import java.util.jar.JarEntry;
|
|
import java.util.jar.JarFile;
|
|
|
|
final class NativeLib {
|
|
private static final Linker LINKER = Linker.nativeLinker();
|
|
private static SymbolLookup LIB;
|
|
private static final String NATIVES_RESOURCE_ROOT = "/natives";
|
|
private static final Object NATIVE_EXTRACT_LOCK = new Object();
|
|
private static String cachedExtractKey;
|
|
private static Path cachedExtractDir;
|
|
private static String loadedLibraryName;
|
|
|
|
static {
|
|
loadNativeLibrary();
|
|
try {
|
|
Arena arena = Arena.ofShared();
|
|
// Try the loaded library name first (for System.load() path case)
|
|
try {
|
|
LIB = SymbolLookup.libraryLookup(loadedLibraryName, arena);
|
|
} catch (Throwable inner1) {
|
|
// Try with 'lib' prefix if not already present (for System.loadLibrary() case)
|
|
String nameWithLib = loadedLibraryName.startsWith("lib") ? loadedLibraryName : "lib" + loadedLibraryName;
|
|
try {
|
|
LIB = SymbolLookup.libraryLookup(nameWithLib, arena);
|
|
} catch (Throwable inner2) {
|
|
// Last fallback: use LINKER.defaultLookup()
|
|
LIB = LINKER.defaultLookup();
|
|
}
|
|
}
|
|
} catch (Throwable e) {
|
|
throw new ExceptionInInitializerError("Failed to initialize library symbols: " + e.getMessage());
|
|
}
|
|
}
|
|
|
|
private static void loadNativeLibrary() {
|
|
String osName = System.getProperty("os.name", "").toLowerCase(java.util.Locale.ROOT);
|
|
String osArch = System.getProperty("os.arch", "").toLowerCase(java.util.Locale.ROOT);
|
|
|
|
String libName;
|
|
String libExt;
|
|
if (osName.contains("mac") || osName.contains("darwin")) {
|
|
libName = "libkreuzberg_ffi";
|
|
libExt = ".dylib";
|
|
} else if (osName.contains("win")) {
|
|
libName = "kreuzberg_ffi";
|
|
libExt = ".dll";
|
|
} else {
|
|
libName = "libkreuzberg_ffi";
|
|
libExt = ".so";
|
|
}
|
|
|
|
String nativesRid = resolveNativesRid(osName, osArch);
|
|
String nativesDir = NATIVES_RESOURCE_ROOT + "/" + nativesRid;
|
|
|
|
Path extracted = tryExtractAndLoadFromResources(nativesDir, libName, libExt);
|
|
if (extracted != null) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
System.loadLibrary("kreuzberg_ffi");
|
|
// Find the full path by searching java.library.path
|
|
loadedLibraryName = findLoadedLibraryPath("kreuzberg_ffi", libName, libExt);
|
|
} catch (UnsatisfiedLinkError e) {
|
|
String msg = "Failed to load kreuzberg_ffi native library. Expected resource: " + nativesDir + "/" + libName
|
|
+ libExt + " (RID: " + nativesRid + "). "
|
|
+ "Ensure the library is bundled in the JAR under natives/{os-arch}/, "
|
|
+ "or place it on the system library path (java.library.path).";
|
|
UnsatisfiedLinkError out = new UnsatisfiedLinkError(msg + " Original error: " + e.getMessage());
|
|
out.initCause(e);
|
|
throw out;
|
|
}
|
|
}
|
|
|
|
private static Path tryExtractAndLoadFromResources(String nativesDir, String libName, String libExt) {
|
|
String resourcePath = nativesDir + "/" + libName + libExt;
|
|
URL resource = NativeLib.class.getResource(resourcePath);
|
|
if (resource == null) {
|
|
return null;
|
|
}
|
|
|
|
try {
|
|
Path tempDir = extractOrReuseNativeDirectory(nativesDir);
|
|
Path libPath = tempDir.resolve(libName + libExt);
|
|
if (!Files.exists(libPath)) {
|
|
throw new UnsatisfiedLinkError("Missing extracted native library: " + libPath);
|
|
}
|
|
System.load(libPath.toAbsolutePath().toString());
|
|
loadedLibraryName = libPath.toAbsolutePath().toString();
|
|
return libPath;
|
|
} catch (Exception e) {
|
|
System.err.println("[NativeLib] Failed to extract and load native library from resources: " + e.getMessage());
|
|
return null;
|
|
}
|
|
}
|
|
|
|
private static Path extractOrReuseNativeDirectory(String nativesDir) throws Exception {
|
|
URL location = NativeLib.class.getProtectionDomain().getCodeSource().getLocation();
|
|
if (location == null) {
|
|
throw new IllegalStateException("Missing code source location for kreuzberg_ffi JAR");
|
|
}
|
|
|
|
Path codePath = Path.of(location.toURI());
|
|
String key = codePath.toAbsolutePath() + "::" + nativesDir;
|
|
|
|
synchronized (NATIVE_EXTRACT_LOCK) {
|
|
if (cachedExtractDir != null && key.equals(cachedExtractKey)) {
|
|
return cachedExtractDir;
|
|
}
|
|
Path tempDir = Files.createTempDirectory("kreuzberg_ffi_native");
|
|
tempDir.toFile().deleteOnExit();
|
|
List<Path> extracted = extractNativeDirectory(codePath, nativesDir, tempDir);
|
|
if (extracted.isEmpty()) {
|
|
throw new IllegalStateException("No native files extracted from resources dir: " + nativesDir);
|
|
}
|
|
cachedExtractKey = key;
|
|
cachedExtractDir = tempDir;
|
|
return tempDir;
|
|
}
|
|
}
|
|
|
|
private static List<Path> extractNativeDirectory(Path codePath, String nativesDir, Path destDir) throws Exception {
|
|
if (!Files.exists(destDir) || !Files.isDirectory(destDir)) {
|
|
throw new IllegalArgumentException("Destination directory does not exist: " + destDir);
|
|
}
|
|
|
|
String prefix = nativesDir.startsWith("/") ? nativesDir.substring(1) : nativesDir;
|
|
if (!prefix.endsWith("/")) {
|
|
prefix = prefix + "/";
|
|
}
|
|
|
|
if (Files.isDirectory(codePath)) {
|
|
Path nativesPath = codePath.resolve(prefix);
|
|
if (!Files.exists(nativesPath) || !Files.isDirectory(nativesPath)) {
|
|
return List.of();
|
|
}
|
|
return copyDirectory(nativesPath, destDir);
|
|
}
|
|
|
|
List<Path> extracted = new ArrayList<>();
|
|
try (JarFile jar = new JarFile(codePath.toFile())) {
|
|
Enumeration<JarEntry> entries = jar.entries();
|
|
while (entries.hasMoreElements()) {
|
|
JarEntry entry = entries.nextElement();
|
|
String name = entry.getName();
|
|
if (!name.startsWith(prefix) || entry.isDirectory()) {
|
|
continue;
|
|
}
|
|
String relative = name.substring(prefix.length());
|
|
Path out = safeResolve(destDir, relative);
|
|
Files.createDirectories(out.getParent());
|
|
try (var in = jar.getInputStream(entry)) {
|
|
Files.copy(in, out, StandardCopyOption.REPLACE_EXISTING);
|
|
}
|
|
out.toFile().deleteOnExit();
|
|
extracted.add(out);
|
|
}
|
|
}
|
|
return extracted;
|
|
}
|
|
|
|
private static List<Path> copyDirectory(Path srcDir, Path destDir) throws Exception {
|
|
List<Path> copied = new ArrayList<>();
|
|
try (var paths = Files.walk(srcDir)) {
|
|
for (Path src : (Iterable<Path>) paths::iterator) {
|
|
if (Files.isDirectory(src)) {
|
|
continue;
|
|
}
|
|
Path relative = srcDir.relativize(src);
|
|
Path out = safeResolve(destDir, relative.toString());
|
|
Files.createDirectories(out.getParent());
|
|
Files.copy(src, out, StandardCopyOption.REPLACE_EXISTING);
|
|
out.toFile().deleteOnExit();
|
|
copied.add(out);
|
|
}
|
|
}
|
|
return copied;
|
|
}
|
|
|
|
private static Path safeResolve(Path destDir, String relative) throws Exception {
|
|
Path normalizedDest = destDir.toAbsolutePath().normalize();
|
|
Path out = normalizedDest.resolve(relative).normalize();
|
|
if (!out.startsWith(normalizedDest)) {
|
|
throw new SecurityException("Blocked extracting native file outside destination directory: " + relative);
|
|
}
|
|
return out;
|
|
}
|
|
|
|
private static String resolveNativesRid(String osName, String osArch) {
|
|
String arch;
|
|
if (osArch.contains("aarch64") || osArch.contains("arm64")) {
|
|
arch = "arm64";
|
|
} else if (osArch.contains("x86_64") || osArch.contains("amd64")) {
|
|
arch = "x86_64";
|
|
} else {
|
|
arch = osArch.replaceAll("[^a-z0-9_]+", "");
|
|
}
|
|
|
|
String os;
|
|
if (osName.contains("mac") || osName.contains("darwin")) {
|
|
os = "macos";
|
|
} else if (osName.contains("win")) {
|
|
os = "windows";
|
|
} else {
|
|
os = "linux";
|
|
}
|
|
|
|
return os + "-" + arch;
|
|
}
|
|
|
|
private static String findLoadedLibraryPath(String libName, String fullLibName, String libExt) {
|
|
// Search java.library.path for the library file
|
|
String javaLibPath = System.getProperty("java.library.path");
|
|
if (javaLibPath != null) {
|
|
for (String path : javaLibPath.split(File.pathSeparator)) {
|
|
Path libPath = Paths.get(path, fullLibName + libExt);
|
|
if (java.nio.file.Files.exists(libPath)) {
|
|
try {
|
|
return libPath.toRealPath().toString();
|
|
} catch (java.io.IOException e) {
|
|
return libPath.toAbsolutePath().toString();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// Fallback: try just the library name (may work on some systems)
|
|
return libName;
|
|
}
|
|
|
|
|
|
static final MethodHandle KREUZBERG_EXTRACT_BYTES = LINKER.downcallHandle(
|
|
LIB.find("kreuzberg_extract_bytes").orElseThrow(),
|
|
FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.JAVA_LONG, ValueLayout.ADDRESS, ValueLayout.ADDRESS)
|
|
);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_EXTRACT_FILE = LINKER.downcallHandle(
|
|
LIB.find("kreuzberg_extract_file").orElseThrow(),
|
|
FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.ADDRESS)
|
|
);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_EXTRACT_FILE_SYNC = LINKER.downcallHandle(
|
|
LIB.find("kreuzberg_extract_file_sync").orElseThrow(),
|
|
FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.ADDRESS)
|
|
);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_EXTRACT_BYTES_SYNC = LINKER.downcallHandle(
|
|
LIB.find("kreuzberg_extract_bytes_sync").orElseThrow(),
|
|
FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.JAVA_LONG, ValueLayout.ADDRESS, ValueLayout.ADDRESS)
|
|
);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_BATCH_EXTRACT_FILES_SYNC = LINKER.downcallHandle(
|
|
LIB.find("kreuzberg_batch_extract_files_sync").orElseThrow(),
|
|
FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.ADDRESS)
|
|
);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_BATCH_EXTRACT_BYTES_SYNC = LINKER.downcallHandle(
|
|
LIB.find("kreuzberg_batch_extract_bytes_sync").orElseThrow(),
|
|
FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.ADDRESS)
|
|
);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_BATCH_EXTRACT_FILES = LINKER.downcallHandle(
|
|
LIB.find("kreuzberg_batch_extract_files").orElseThrow(),
|
|
FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.ADDRESS)
|
|
);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_BATCH_EXTRACT_BYTES = LINKER.downcallHandle(
|
|
LIB.find("kreuzberg_batch_extract_bytes").orElseThrow(),
|
|
FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.ADDRESS)
|
|
);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_DETECT_MIME_TYPE_FROM_BYTES = LINKER.downcallHandle(
|
|
LIB.find("kreuzberg_detect_mime_type_from_bytes").orElseThrow(),
|
|
FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.JAVA_LONG)
|
|
);
|
|
|
|
static final MethodHandle KREUZBERG_DETECT_MIME_TYPE_FROM_BYTES_LEN = LINKER.downcallHandle(
|
|
LIB.find("kreuzberg_detect_mime_type_from_bytes_len").orElseThrow(),
|
|
FunctionDescriptor.of(ValueLayout.JAVA_LONG, ValueLayout.ADDRESS, ValueLayout.JAVA_LONG)
|
|
);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_GET_EXTENSIONS_FOR_MIME = LINKER.downcallHandle(
|
|
LIB.find("kreuzberg_get_extensions_for_mime").orElseThrow(),
|
|
FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS)
|
|
);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_LIST_EMBEDDING_BACKENDS = LINKER.downcallHandle(
|
|
LIB.find("kreuzberg_list_embedding_backends").orElseThrow(),
|
|
FunctionDescriptor.of(ValueLayout.ADDRESS)
|
|
);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_LIST_DOCUMENT_EXTRACTORS = LINKER.downcallHandle(
|
|
LIB.find("kreuzberg_list_document_extractors").orElseThrow(),
|
|
FunctionDescriptor.of(ValueLayout.ADDRESS)
|
|
);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_LIST_OCR_BACKENDS = LINKER.downcallHandle(
|
|
LIB.find("kreuzberg_list_ocr_backends").orElseThrow(),
|
|
FunctionDescriptor.of(ValueLayout.ADDRESS)
|
|
);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_LIST_POST_PROCESSORS = LINKER.downcallHandle(
|
|
LIB.find("kreuzberg_list_post_processors").orElseThrow(),
|
|
FunctionDescriptor.of(ValueLayout.ADDRESS)
|
|
);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_LIST_RENDERERS = LINKER.downcallHandle(
|
|
LIB.find("kreuzberg_list_renderers").orElseThrow(),
|
|
FunctionDescriptor.of(ValueLayout.ADDRESS)
|
|
);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_LIST_VALIDATORS = LINKER.downcallHandle(
|
|
LIB.find("kreuzberg_list_validators").orElseThrow(),
|
|
FunctionDescriptor.of(ValueLayout.ADDRESS)
|
|
);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_COMPARE = LINKER.downcallHandle(
|
|
LIB.find("kreuzberg_compare").orElseThrow(),
|
|
FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.ADDRESS)
|
|
);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_EMBED_TEXTS_ASYNC = LINKER.downcallHandle(
|
|
LIB.find("kreuzberg_embed_texts_async").orElseThrow(),
|
|
FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.ADDRESS)
|
|
);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_RENDER_PDF_PAGE_TO_PNG = LINKER.downcallHandle(
|
|
LIB.find("kreuzberg_render_pdf_page_to_png").orElseThrow(),
|
|
FunctionDescriptor.of(
|
|
ValueLayout.JAVA_INT,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.JAVA_LONG,
|
|
ValueLayout.JAVA_LONG,
|
|
ValueLayout.JAVA_INT,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS
|
|
)
|
|
);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_DETECT_MIME_TYPE = LINKER.downcallHandle(
|
|
LIB.find("kreuzberg_detect_mime_type").orElseThrow(),
|
|
FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.JAVA_INT)
|
|
);
|
|
|
|
static final MethodHandle KREUZBERG_DETECT_MIME_TYPE_LEN = LINKER.downcallHandle(
|
|
LIB.find("kreuzberg_detect_mime_type_len").orElseThrow(),
|
|
FunctionDescriptor.of(ValueLayout.JAVA_LONG, ValueLayout.ADDRESS, ValueLayout.JAVA_INT)
|
|
);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_EMBED_TEXTS = LINKER.downcallHandle(
|
|
LIB.find("kreuzberg_embed_texts").orElseThrow(),
|
|
FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.ADDRESS)
|
|
);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_GET_EMBEDDING_PRESET = LINKER.downcallHandle(
|
|
LIB.find("kreuzberg_get_embedding_preset").orElseThrow(),
|
|
FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS)
|
|
);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_LIST_EMBEDDING_PRESETS = LINKER.downcallHandle(
|
|
LIB.find("kreuzberg_list_embedding_presets").orElseThrow(),
|
|
FunctionDescriptor.of(ValueLayout.ADDRESS)
|
|
);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_FREE_STRING = LINKER.downcallHandle(
|
|
LIB.find("kreuzberg_free_string").orElseThrow(),
|
|
FunctionDescriptor.ofVoid(ValueLayout.ADDRESS)
|
|
);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_FREE_BYTES = LINKER.downcallHandle(
|
|
LIB.find("kreuzberg_free_bytes").orElseThrow(),
|
|
FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_LONG, ValueLayout.JAVA_LONG)
|
|
);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_LAST_ERROR_CODE = LINKER.downcallHandle(
|
|
LIB.find("kreuzberg_last_error_code").orElse(null),
|
|
FunctionDescriptor.of(ValueLayout.JAVA_INT)
|
|
);
|
|
|
|
static final MethodHandle KREUZBERG_LAST_ERROR_CONTEXT = LINKER.downcallHandle(
|
|
LIB.find("kreuzberg_last_error_context").orElse(null),
|
|
FunctionDescriptor.of(ValueLayout.ADDRESS)
|
|
);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_EXTRACTION_RESULT_TO_JSON = LIB.find("kreuzberg_extraction_result_to_json")
|
|
.map(s -> LINKER.downcallHandle(s, FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS)))
|
|
.orElse(null);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_EXTRACTION_RESULT_FREE = LINKER.downcallHandle(
|
|
LIB.find("kreuzberg_extraction_result_free").orElseThrow(),
|
|
FunctionDescriptor.ofVoid(ValueLayout.ADDRESS)
|
|
);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_EXTRACTION_DIFF_TO_JSON = LIB.find("kreuzberg_extraction_diff_to_json")
|
|
.map(s -> LINKER.downcallHandle(s, FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS)))
|
|
.orElse(null);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_EXTRACTION_DIFF_FREE = LINKER.downcallHandle(
|
|
LIB.find("kreuzberg_extraction_diff_free").orElseThrow(),
|
|
FunctionDescriptor.ofVoid(ValueLayout.ADDRESS)
|
|
);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_EMBEDDING_PRESET_TO_JSON = LIB.find("kreuzberg_embedding_preset_to_json")
|
|
.map(s -> LINKER.downcallHandle(s, FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS)))
|
|
.orElse(null);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_EMBEDDING_PRESET_FREE = LINKER.downcallHandle(
|
|
LIB.find("kreuzberg_embedding_preset_free").orElseThrow(),
|
|
FunctionDescriptor.ofVoid(ValueLayout.ADDRESS)
|
|
);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_EXTRACTION_CONFIG_FROM_JSON = LINKER.downcallHandle(
|
|
LIB.find("kreuzberg_extraction_config_from_json").orElseThrow(),
|
|
FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS)
|
|
);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_EXTRACTION_CONFIG_FREE = LINKER.downcallHandle(
|
|
LIB.find("kreuzberg_extraction_config_free").orElseThrow(),
|
|
FunctionDescriptor.ofVoid(ValueLayout.ADDRESS)
|
|
);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_EXTRACTION_RESULT_FROM_JSON = LINKER.downcallHandle(
|
|
LIB.find("kreuzberg_extraction_result_from_json").orElseThrow(),
|
|
FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS)
|
|
);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_DIFF_OPTIONS_FROM_JSON = LINKER.downcallHandle(
|
|
LIB.find("kreuzberg_diff_options_from_json").orElseThrow(),
|
|
FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS)
|
|
);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_DIFF_OPTIONS_FREE = LINKER.downcallHandle(
|
|
LIB.find("kreuzberg_diff_options_free").orElseThrow(),
|
|
FunctionDescriptor.ofVoid(ValueLayout.ADDRESS)
|
|
);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_EMBEDDING_CONFIG_FROM_JSON = LINKER.downcallHandle(
|
|
LIB.find("kreuzberg_embedding_config_from_json").orElseThrow(),
|
|
FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS)
|
|
);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_EMBEDDING_CONFIG_FREE = LINKER.downcallHandle(
|
|
LIB.find("kreuzberg_embedding_config_free").orElseThrow(),
|
|
FunctionDescriptor.ofVoid(ValueLayout.ADDRESS)
|
|
);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_REGISTER_OCR_BACKEND = LIB
|
|
.find("kreuzberg_register_ocr_backend")
|
|
.map(s -> LINKER.downcallHandle(s, FunctionDescriptor.of(ValueLayout.JAVA_INT,
|
|
ValueLayout.ADDRESS, MemoryLayout.structLayout(
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS
|
|
), ValueLayout.ADDRESS, ValueLayout.ADDRESS)))
|
|
.orElse(null);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_UNREGISTER_OCR_BACKEND = LIB
|
|
.find("kreuzberg_unregister_ocr_backend")
|
|
.map(s -> LINKER.downcallHandle(s,
|
|
FunctionDescriptor.of(ValueLayout.JAVA_INT, ValueLayout.ADDRESS, ValueLayout.ADDRESS)))
|
|
.orElse(null);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_CLEAR_OCR_BACKEND = LIB
|
|
.find("kreuzberg_clear_ocr_backend")
|
|
.map(s -> LINKER.downcallHandle(s,
|
|
FunctionDescriptor.of(ValueLayout.JAVA_INT, ValueLayout.ADDRESS)))
|
|
.orElse(null);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_REGISTER_POST_PROCESSOR = LIB
|
|
.find("kreuzberg_register_post_processor")
|
|
.map(s -> LINKER.downcallHandle(s, FunctionDescriptor.of(ValueLayout.JAVA_INT,
|
|
ValueLayout.ADDRESS, MemoryLayout.structLayout(
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS
|
|
), ValueLayout.ADDRESS, ValueLayout.ADDRESS)))
|
|
.orElse(null);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_UNREGISTER_POST_PROCESSOR = LIB
|
|
.find("kreuzberg_unregister_post_processor")
|
|
.map(s -> LINKER.downcallHandle(s,
|
|
FunctionDescriptor.of(ValueLayout.JAVA_INT, ValueLayout.ADDRESS, ValueLayout.ADDRESS)))
|
|
.orElse(null);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_CLEAR_POST_PROCESSOR = LIB
|
|
.find("kreuzberg_clear_post_processor")
|
|
.map(s -> LINKER.downcallHandle(s,
|
|
FunctionDescriptor.of(ValueLayout.JAVA_INT, ValueLayout.ADDRESS)))
|
|
.orElse(null);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_REGISTER_VALIDATOR = LIB
|
|
.find("kreuzberg_register_validator")
|
|
.map(s -> LINKER.downcallHandle(s, FunctionDescriptor.of(ValueLayout.JAVA_INT,
|
|
ValueLayout.ADDRESS, MemoryLayout.structLayout(
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS
|
|
), ValueLayout.ADDRESS, ValueLayout.ADDRESS)))
|
|
.orElse(null);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_UNREGISTER_VALIDATOR = LIB
|
|
.find("kreuzberg_unregister_validator")
|
|
.map(s -> LINKER.downcallHandle(s,
|
|
FunctionDescriptor.of(ValueLayout.JAVA_INT, ValueLayout.ADDRESS, ValueLayout.ADDRESS)))
|
|
.orElse(null);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_CLEAR_VALIDATOR = LIB
|
|
.find("kreuzberg_clear_validator")
|
|
.map(s -> LINKER.downcallHandle(s,
|
|
FunctionDescriptor.of(ValueLayout.JAVA_INT, ValueLayout.ADDRESS)))
|
|
.orElse(null);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_REGISTER_EMBEDDING_BACKEND = LIB
|
|
.find("kreuzberg_register_embedding_backend")
|
|
.map(s -> LINKER.downcallHandle(s, FunctionDescriptor.of(ValueLayout.JAVA_INT,
|
|
ValueLayout.ADDRESS, MemoryLayout.structLayout(
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS
|
|
), ValueLayout.ADDRESS, ValueLayout.ADDRESS)))
|
|
.orElse(null);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_UNREGISTER_EMBEDDING_BACKEND = LIB
|
|
.find("kreuzberg_unregister_embedding_backend")
|
|
.map(s -> LINKER.downcallHandle(s,
|
|
FunctionDescriptor.of(ValueLayout.JAVA_INT, ValueLayout.ADDRESS, ValueLayout.ADDRESS)))
|
|
.orElse(null);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_CLEAR_EMBEDDING_BACKEND = LIB
|
|
.find("kreuzberg_clear_embedding_backend")
|
|
.map(s -> LINKER.downcallHandle(s,
|
|
FunctionDescriptor.of(ValueLayout.JAVA_INT, ValueLayout.ADDRESS)))
|
|
.orElse(null);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_REGISTER_DOCUMENT_EXTRACTOR = LIB
|
|
.find("kreuzberg_register_document_extractor")
|
|
.map(s -> LINKER.downcallHandle(s, FunctionDescriptor.of(ValueLayout.JAVA_INT,
|
|
ValueLayout.ADDRESS, MemoryLayout.structLayout(
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS
|
|
), ValueLayout.ADDRESS, ValueLayout.ADDRESS)))
|
|
.orElse(null);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_UNREGISTER_DOCUMENT_EXTRACTOR = LIB
|
|
.find("kreuzberg_unregister_document_extractor")
|
|
.map(s -> LINKER.downcallHandle(s,
|
|
FunctionDescriptor.of(ValueLayout.JAVA_INT, ValueLayout.ADDRESS, ValueLayout.ADDRESS)))
|
|
.orElse(null);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_CLEAR_DOCUMENT_EXTRACTOR = LIB
|
|
.find("kreuzberg_clear_document_extractor")
|
|
.map(s -> LINKER.downcallHandle(s,
|
|
FunctionDescriptor.of(ValueLayout.JAVA_INT, ValueLayout.ADDRESS)))
|
|
.orElse(null);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_REGISTER_RENDERER = LIB
|
|
.find("kreuzberg_register_renderer")
|
|
.map(s -> LINKER.downcallHandle(s, FunctionDescriptor.of(ValueLayout.JAVA_INT,
|
|
ValueLayout.ADDRESS, MemoryLayout.structLayout(
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS,
|
|
ValueLayout.ADDRESS
|
|
), ValueLayout.ADDRESS, ValueLayout.ADDRESS)))
|
|
.orElse(null);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_UNREGISTER_RENDERER = LIB
|
|
.find("kreuzberg_unregister_renderer")
|
|
.map(s -> LINKER.downcallHandle(s,
|
|
FunctionDescriptor.of(ValueLayout.JAVA_INT, ValueLayout.ADDRESS, ValueLayout.ADDRESS)))
|
|
.orElse(null);
|
|
|
|
|
|
static final MethodHandle KREUZBERG_CLEAR_RENDERER = LIB
|
|
.find("kreuzberg_clear_renderer")
|
|
.map(s -> LINKER.downcallHandle(s,
|
|
FunctionDescriptor.of(ValueLayout.JAVA_INT, ValueLayout.ADDRESS)))
|
|
.orElse(null);
|
|
|
|
|
|
}
|