cactus-react-native 1.2.1 → 1.5.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 +765 -33
- package/android/CMakeLists.txt +4 -3
- package/android/src/main/java/com/margelo/nitro/cactus/HybridCactusFileSystem.kt +20 -1
- package/android/src/main/jniLibs/arm64-v8a/libcactus.a +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libcactus_util.a +0 -0
- package/cpp/HybridCactus.cpp +231 -19
- package/cpp/HybridCactus.hpp +25 -3
- package/cpp/HybridCactusIndex.cpp +325 -0
- package/cpp/HybridCactusIndex.hpp +43 -0
- package/cpp/HybridCactusUtil.cpp +3 -3
- package/cpp/HybridCactusUtil.hpp +2 -1
- package/cpp/cactus_ffi.h +107 -2
- package/cpp/cactus_util.h +1 -1
- package/ios/HybridCactusFileSystem.swift +23 -2
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/cactus.h +2 -0
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/cactus_ffi.h +107 -2
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/cactus_telemetry.h +656 -0
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/{ffi_utils.h → cactus_utils.h} +145 -18
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/engine.h +135 -7
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/gemma_tools.h +549 -0
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/graph.h +193 -26
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/kernel.h +54 -195
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/kernel_utils.h +399 -140
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Info.plist +0 -0
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/cactus +0 -0
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/cactus.h +2 -0
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/cactus_ffi.h +107 -2
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/cactus_telemetry.h +656 -0
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/{ffi_utils.h → cactus_utils.h} +145 -18
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/engine.h +135 -7
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/gemma_tools.h +549 -0
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/graph.h +193 -26
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/kernel.h +54 -195
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/kernel_utils.h +399 -140
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Info.plist +0 -0
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/_CodeSignature/CodeResources +1 -1
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/cactus +0 -0
- package/ios/cactus_util.xcframework/Info.plist +4 -4
- package/ios/cactus_util.xcframework/ios-arm64/cactus_util.framework/Headers/cactus_util.h +1 -1
- package/ios/cactus_util.xcframework/ios-arm64/cactus_util.framework/Headers/database.h +27 -0
- package/ios/cactus_util.xcframework/ios-arm64/cactus_util.framework/Info.plist +0 -0
- package/ios/cactus_util.xcframework/ios-arm64/cactus_util.framework/cactus_util +0 -0
- package/ios/cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework/Headers/cactus_util.h +1 -1
- package/ios/cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework/Headers/database.h +27 -0
- package/ios/cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework/Info.plist +0 -0
- package/ios/cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework/_CodeSignature/CodeResources +3 -3
- package/ios/cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework/cactus_util +0 -0
- package/lib/module/api/Database.js +12 -95
- package/lib/module/api/Database.js.map +1 -1
- package/lib/module/classes/CactusIndex.js +45 -0
- package/lib/module/classes/CactusIndex.js.map +1 -0
- package/lib/module/classes/CactusLM.js +65 -17
- package/lib/module/classes/CactusLM.js.map +1 -1
- package/lib/module/classes/CactusSTT.js +104 -17
- package/lib/module/classes/CactusSTT.js.map +1 -1
- package/lib/module/config/CactusConfig.js +2 -0
- package/lib/module/config/CactusConfig.js.map +1 -1
- package/lib/module/constants/packageVersion.js +1 -1
- package/lib/module/hooks/useCactusIndex.js +175 -0
- package/lib/module/hooks/useCactusIndex.js.map +1 -0
- package/lib/module/hooks/useCactusLM.js +68 -7
- package/lib/module/hooks/useCactusLM.js.map +1 -1
- package/lib/module/hooks/useCactusSTT.js +102 -6
- package/lib/module/hooks/useCactusSTT.js.map +1 -1
- package/lib/module/index.js +2 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/models.js +336 -0
- package/lib/module/models.js.map +1 -0
- package/lib/module/native/Cactus.js +61 -13
- package/lib/module/native/Cactus.js.map +1 -1
- package/lib/module/native/CactusFileSystem.js +3 -0
- package/lib/module/native/CactusFileSystem.js.map +1 -1
- package/lib/module/native/CactusIndex.js +32 -0
- package/lib/module/native/CactusIndex.js.map +1 -0
- package/lib/module/native/CactusUtil.js +16 -3
- package/lib/module/native/CactusUtil.js.map +1 -1
- package/lib/module/native/index.js +1 -0
- package/lib/module/native/index.js.map +1 -1
- package/lib/module/specs/CactusIndex.nitro.js +4 -0
- package/lib/module/specs/CactusIndex.nitro.js.map +1 -0
- package/lib/module/telemetry/Telemetry.js +3 -1
- package/lib/module/telemetry/Telemetry.js.map +1 -1
- package/lib/module/types/CactusIndex.js +2 -0
- package/lib/module/types/{CactusModel.js.map → CactusIndex.js.map} +1 -1
- package/lib/module/types/CactusLM.js +2 -0
- package/lib/module/types/CactusSTT.js +2 -0
- package/lib/module/types/common.js +2 -0
- package/lib/module/types/{CactusSTTModel.js.map → common.js.map} +1 -1
- package/lib/typescript/src/api/Database.d.ts +4 -7
- package/lib/typescript/src/api/Database.d.ts.map +1 -1
- package/lib/typescript/src/classes/CactusIndex.d.ts +15 -0
- package/lib/typescript/src/classes/CactusIndex.d.ts.map +1 -0
- package/lib/typescript/src/classes/CactusLM.d.ts +12 -5
- package/lib/typescript/src/classes/CactusLM.d.ts.map +1 -1
- package/lib/typescript/src/classes/CactusSTT.d.ts +15 -5
- package/lib/typescript/src/classes/CactusSTT.d.ts.map +1 -1
- package/lib/typescript/src/config/CactusConfig.d.ts +1 -0
- package/lib/typescript/src/config/CactusConfig.d.ts.map +1 -1
- package/lib/typescript/src/constants/packageVersion.d.ts +1 -1
- package/lib/typescript/src/hooks/useCactusIndex.d.ts +14 -0
- package/lib/typescript/src/hooks/useCactusIndex.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useCactusLM.d.ts +6 -4
- package/lib/typescript/src/hooks/useCactusLM.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useCactusSTT.d.ts +13 -5
- package/lib/typescript/src/hooks/useCactusSTT.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +6 -4
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/models.d.ts +6 -0
- package/lib/typescript/src/models.d.ts.map +1 -0
- package/lib/typescript/src/native/Cactus.d.ts +10 -3
- package/lib/typescript/src/native/Cactus.d.ts.map +1 -1
- package/lib/typescript/src/native/CactusFileSystem.d.ts +1 -0
- package/lib/typescript/src/native/CactusFileSystem.d.ts.map +1 -1
- package/lib/typescript/src/native/CactusIndex.d.ts +12 -0
- package/lib/typescript/src/native/CactusIndex.d.ts.map +1 -0
- package/lib/typescript/src/native/CactusUtil.d.ts.map +1 -1
- package/lib/typescript/src/native/index.d.ts +1 -0
- package/lib/typescript/src/native/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/Cactus.nitro.d.ts +9 -2
- package/lib/typescript/src/specs/Cactus.nitro.d.ts.map +1 -1
- package/lib/typescript/src/specs/CactusFileSystem.nitro.d.ts +1 -0
- package/lib/typescript/src/specs/CactusFileSystem.nitro.d.ts.map +1 -1
- package/lib/typescript/src/specs/CactusIndex.nitro.d.ts +24 -0
- package/lib/typescript/src/specs/CactusIndex.nitro.d.ts.map +1 -0
- package/lib/typescript/src/specs/CactusUtil.nitro.d.ts +1 -1
- package/lib/typescript/src/specs/CactusUtil.nitro.d.ts.map +1 -1
- package/lib/typescript/src/types/CactusIndex.d.ts +34 -0
- package/lib/typescript/src/types/CactusIndex.d.ts.map +1 -0
- package/lib/typescript/src/types/CactusLM.d.ts +19 -0
- package/lib/typescript/src/types/CactusLM.d.ts.map +1 -1
- package/lib/typescript/src/types/CactusSTT.d.ts +21 -1
- package/lib/typescript/src/types/CactusSTT.d.ts.map +1 -1
- package/lib/typescript/src/types/common.d.ts +28 -0
- package/lib/typescript/src/types/common.d.ts.map +1 -0
- package/nitro.json +3 -0
- package/nitrogen/generated/android/c++/JDeviceInfo.hpp +1 -1
- package/nitrogen/generated/android/c++/JFunc_void_double.hpp +1 -1
- package/nitrogen/generated/android/c++/JHybridCactusCryptoSpec.cpp +1 -1
- package/nitrogen/generated/android/c++/JHybridCactusCryptoSpec.hpp +1 -1
- package/nitrogen/generated/android/c++/JHybridCactusDeviceInfoSpec.cpp +1 -1
- package/nitrogen/generated/android/c++/JHybridCactusDeviceInfoSpec.hpp +1 -1
- package/nitrogen/generated/android/c++/JHybridCactusFileSystemSpec.cpp +17 -1
- package/nitrogen/generated/android/c++/JHybridCactusFileSystemSpec.hpp +2 -1
- package/nitrogen/generated/android/c++/JHybridCactusImageSpec.cpp +1 -1
- package/nitrogen/generated/android/c++/JHybridCactusImageSpec.hpp +1 -1
- package/nitrogen/generated/android/cactus+autolinking.cmake +2 -1
- package/nitrogen/generated/android/cactus+autolinking.gradle +1 -1
- package/nitrogen/generated/android/cactusOnLoad.cpp +11 -1
- package/nitrogen/generated/android/cactusOnLoad.hpp +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/DeviceInfo.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/Func_void_double.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/HybridCactusCryptoSpec.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/HybridCactusDeviceInfoSpec.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/HybridCactusFileSystemSpec.kt +5 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/HybridCactusImageSpec.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/cactusOnLoad.kt +1 -1
- package/nitrogen/generated/ios/Cactus+autolinking.rb +1 -1
- package/nitrogen/generated/ios/Cactus-Swift-Cxx-Bridge.cpp +1 -1
- package/nitrogen/generated/ios/Cactus-Swift-Cxx-Bridge.hpp +1 -1
- package/nitrogen/generated/ios/Cactus-Swift-Cxx-Umbrella.hpp +1 -1
- package/nitrogen/generated/ios/CactusAutolinking.mm +11 -1
- package/nitrogen/generated/ios/CactusAutolinking.swift +1 -1
- package/nitrogen/generated/ios/c++/HybridCactusCryptoSpecSwift.cpp +1 -1
- package/nitrogen/generated/ios/c++/HybridCactusCryptoSpecSwift.hpp +1 -1
- package/nitrogen/generated/ios/c++/HybridCactusDeviceInfoSpecSwift.cpp +1 -1
- package/nitrogen/generated/ios/c++/HybridCactusDeviceInfoSpecSwift.hpp +1 -1
- package/nitrogen/generated/ios/c++/HybridCactusFileSystemSpecSwift.cpp +1 -1
- package/nitrogen/generated/ios/c++/HybridCactusFileSystemSpecSwift.hpp +9 -1
- package/nitrogen/generated/ios/c++/HybridCactusImageSpecSwift.cpp +1 -1
- package/nitrogen/generated/ios/c++/HybridCactusImageSpecSwift.hpp +1 -1
- package/nitrogen/generated/ios/swift/DeviceInfo.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_DeviceInfo.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_bool.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_double.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_std__optional_std__string_.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_std__string.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridCactusCryptoSpec.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridCactusCryptoSpec_cxx.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridCactusDeviceInfoSpec.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridCactusDeviceInfoSpec_cxx.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridCactusFileSystemSpec.swift +2 -1
- package/nitrogen/generated/ios/swift/HybridCactusFileSystemSpec_cxx.swift +20 -1
- package/nitrogen/generated/ios/swift/HybridCactusImageSpec.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridCactusImageSpec_cxx.swift +1 -1
- package/nitrogen/generated/shared/c++/CactusIndexGetResult.hpp +84 -0
- package/nitrogen/generated/shared/c++/CactusIndexQueryResult.hpp +79 -0
- package/nitrogen/generated/shared/c++/DeviceInfo.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridCactusCryptoSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridCactusCryptoSpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridCactusDeviceInfoSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridCactusDeviceInfoSpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridCactusFileSystemSpec.cpp +2 -1
- package/nitrogen/generated/shared/c++/HybridCactusFileSystemSpec.hpp +2 -1
- package/nitrogen/generated/shared/c++/HybridCactusImageSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridCactusImageSpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridCactusIndexSpec.cpp +27 -0
- package/nitrogen/generated/shared/c++/HybridCactusIndexSpec.hpp +76 -0
- package/nitrogen/generated/shared/c++/HybridCactusSpec.cpp +8 -1
- package/nitrogen/generated/shared/c++/HybridCactusSpec.hpp +11 -3
- package/nitrogen/generated/shared/c++/HybridCactusUtilSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridCactusUtilSpec.hpp +2 -2
- package/package.json +2 -2
- package/src/api/Database.ts +14 -135
- package/src/classes/CactusIndex.ts +58 -0
- package/src/classes/CactusLM.ts +87 -19
- package/src/classes/CactusSTT.ts +134 -20
- package/src/config/CactusConfig.ts +3 -0
- package/src/constants/packageVersion.ts +1 -1
- package/src/hooks/useCactusIndex.ts +195 -0
- package/src/hooks/useCactusLM.ts +88 -8
- package/src/hooks/useCactusSTT.ts +119 -7
- package/src/index.tsx +22 -2
- package/src/models.ts +344 -0
- package/src/native/Cactus.ts +95 -13
- package/src/native/CactusFileSystem.ts +4 -0
- package/src/native/CactusIndex.ts +54 -0
- package/src/native/CactusUtil.ts +19 -3
- package/src/native/index.ts +1 -0
- package/src/specs/Cactus.nitro.ts +18 -2
- package/src/specs/CactusFileSystem.nitro.ts +2 -0
- package/src/specs/CactusIndex.nitro.ts +31 -0
- package/src/specs/CactusUtil.nitro.ts +1 -1
- package/src/telemetry/Telemetry.ts +1 -1
- package/src/types/CactusIndex.ts +40 -0
- package/src/types/CactusLM.ts +24 -0
- package/src/types/CactusSTT.ts +27 -1
- package/src/types/common.ts +28 -0
- package/android/src/main/jniLibs/arm64-v8a/libcactus_util.so +0 -0
- package/lib/module/types/CactusModel.js +0 -2
- package/lib/module/types/CactusSTTModel.js +0 -2
- package/lib/typescript/src/types/CactusModel.d.ts +0 -13
- package/lib/typescript/src/types/CactusModel.d.ts.map +0 -1
- package/lib/typescript/src/types/CactusSTTModel.d.ts +0 -8
- package/lib/typescript/src/types/CactusSTTModel.d.ts.map +0 -1
- package/src/types/CactusModel.ts +0 -15
- package/src/types/CactusSTTModel.ts +0 -10
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// CactusIndexQueryResult.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#if __has_include(<NitroModules/JSIConverter.hpp>)
|
|
11
|
+
#include <NitroModules/JSIConverter.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
#if __has_include(<NitroModules/NitroDefines.hpp>)
|
|
16
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
17
|
+
#else
|
|
18
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
19
|
+
#endif
|
|
20
|
+
#if __has_include(<NitroModules/JSIHelpers.hpp>)
|
|
21
|
+
#include <NitroModules/JSIHelpers.hpp>
|
|
22
|
+
#else
|
|
23
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
24
|
+
#endif
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
#include <vector>
|
|
29
|
+
|
|
30
|
+
namespace margelo::nitro::cactus {
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* A struct which can be represented as a JavaScript object (CactusIndexQueryResult).
|
|
34
|
+
*/
|
|
35
|
+
struct CactusIndexQueryResult {
|
|
36
|
+
public:
|
|
37
|
+
std::vector<std::vector<double>> ids SWIFT_PRIVATE;
|
|
38
|
+
std::vector<std::vector<double>> scores SWIFT_PRIVATE;
|
|
39
|
+
|
|
40
|
+
public:
|
|
41
|
+
CactusIndexQueryResult() = default;
|
|
42
|
+
explicit CactusIndexQueryResult(std::vector<std::vector<double>> ids, std::vector<std::vector<double>> scores): ids(ids), scores(scores) {}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
} // namespace margelo::nitro::cactus
|
|
46
|
+
|
|
47
|
+
namespace margelo::nitro {
|
|
48
|
+
|
|
49
|
+
// C++ CactusIndexQueryResult <> JS CactusIndexQueryResult (object)
|
|
50
|
+
template <>
|
|
51
|
+
struct JSIConverter<margelo::nitro::cactus::CactusIndexQueryResult> final {
|
|
52
|
+
static inline margelo::nitro::cactus::CactusIndexQueryResult fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
53
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
54
|
+
return margelo::nitro::cactus::CactusIndexQueryResult(
|
|
55
|
+
JSIConverter<std::vector<std::vector<double>>>::fromJSI(runtime, obj.getProperty(runtime, "ids")),
|
|
56
|
+
JSIConverter<std::vector<std::vector<double>>>::fromJSI(runtime, obj.getProperty(runtime, "scores"))
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::cactus::CactusIndexQueryResult& arg) {
|
|
60
|
+
jsi::Object obj(runtime);
|
|
61
|
+
obj.setProperty(runtime, "ids", JSIConverter<std::vector<std::vector<double>>>::toJSI(runtime, arg.ids));
|
|
62
|
+
obj.setProperty(runtime, "scores", JSIConverter<std::vector<std::vector<double>>>::toJSI(runtime, arg.scores));
|
|
63
|
+
return obj;
|
|
64
|
+
}
|
|
65
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
66
|
+
if (!value.isObject()) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
jsi::Object obj = value.getObject(runtime);
|
|
70
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
if (!JSIConverter<std::vector<std::vector<double>>>::canConvert(runtime, obj.getProperty(runtime, "ids"))) return false;
|
|
74
|
+
if (!JSIConverter<std::vector<std::vector<double>>>::canConvert(runtime, obj.getProperty(runtime, "scores"))) return false;
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
} // namespace margelo::nitro
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// HybridCactusCryptoSpec.cpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#include "HybridCactusCryptoSpec.hpp"
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// HybridCactusDeviceInfoSpec.cpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#include "HybridCactusDeviceInfoSpec.hpp"
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// HybridCactusFileSystemSpec.cpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#include "HybridCactusFileSystemSpec.hpp"
|
|
@@ -23,6 +23,7 @@ namespace margelo::nitro::cactus {
|
|
|
23
23
|
prototype.registerHybridMethod("getModelPath", &HybridCactusFileSystemSpec::getModelPath);
|
|
24
24
|
prototype.registerHybridMethod("downloadModel", &HybridCactusFileSystemSpec::downloadModel);
|
|
25
25
|
prototype.registerHybridMethod("deleteModel", &HybridCactusFileSystemSpec::deleteModel);
|
|
26
|
+
prototype.registerHybridMethod("getIndexPath", &HybridCactusFileSystemSpec::getIndexPath);
|
|
26
27
|
});
|
|
27
28
|
}
|
|
28
29
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// HybridCactusFileSystemSpec.hpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#pragma once
|
|
@@ -60,6 +60,7 @@ namespace margelo::nitro::cactus {
|
|
|
60
60
|
virtual std::shared_ptr<Promise<std::string>> getModelPath(const std::string& model) = 0;
|
|
61
61
|
virtual std::shared_ptr<Promise<void>> downloadModel(const std::string& model, const std::string& from, const std::optional<std::function<void(double /* progress */)>>& callback) = 0;
|
|
62
62
|
virtual std::shared_ptr<Promise<void>> deleteModel(const std::string& model) = 0;
|
|
63
|
+
virtual std::shared_ptr<Promise<std::string>> getIndexPath(const std::string& name) = 0;
|
|
63
64
|
|
|
64
65
|
protected:
|
|
65
66
|
// Hybrid Setup
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// HybridCactusImageSpec.cpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#include "HybridCactusImageSpec.hpp"
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridCactusIndexSpec.cpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#include "HybridCactusIndexSpec.hpp"
|
|
9
|
+
|
|
10
|
+
namespace margelo::nitro::cactus {
|
|
11
|
+
|
|
12
|
+
void HybridCactusIndexSpec::loadHybridMethods() {
|
|
13
|
+
// load base methods/properties
|
|
14
|
+
HybridObject::loadHybridMethods();
|
|
15
|
+
// load custom methods/properties
|
|
16
|
+
registerHybrids(this, [](Prototype& prototype) {
|
|
17
|
+
prototype.registerHybridMethod("init", &HybridCactusIndexSpec::init);
|
|
18
|
+
prototype.registerHybridMethod("add", &HybridCactusIndexSpec::add);
|
|
19
|
+
prototype.registerHybridMethod("_delete", &HybridCactusIndexSpec::_delete);
|
|
20
|
+
prototype.registerHybridMethod("get", &HybridCactusIndexSpec::get);
|
|
21
|
+
prototype.registerHybridMethod("query", &HybridCactusIndexSpec::query);
|
|
22
|
+
prototype.registerHybridMethod("compact", &HybridCactusIndexSpec::compact);
|
|
23
|
+
prototype.registerHybridMethod("destroy", &HybridCactusIndexSpec::destroy);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
} // namespace margelo::nitro::cactus
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridCactusIndexSpec.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#if __has_include(<NitroModules/HybridObject.hpp>)
|
|
11
|
+
#include <NitroModules/HybridObject.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
|
|
16
|
+
// Forward declaration of `CactusIndexGetResult` to properly resolve imports.
|
|
17
|
+
namespace margelo::nitro::cactus { struct CactusIndexGetResult; }
|
|
18
|
+
// Forward declaration of `CactusIndexQueryResult` to properly resolve imports.
|
|
19
|
+
namespace margelo::nitro::cactus { struct CactusIndexQueryResult; }
|
|
20
|
+
|
|
21
|
+
#include <NitroModules/Promise.hpp>
|
|
22
|
+
#include <string>
|
|
23
|
+
#include <vector>
|
|
24
|
+
#include <optional>
|
|
25
|
+
#include "CactusIndexGetResult.hpp"
|
|
26
|
+
#include "CactusIndexQueryResult.hpp"
|
|
27
|
+
|
|
28
|
+
namespace margelo::nitro::cactus {
|
|
29
|
+
|
|
30
|
+
using namespace margelo::nitro;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* An abstract base class for `CactusIndex`
|
|
34
|
+
* Inherit this class to create instances of `HybridCactusIndexSpec` in C++.
|
|
35
|
+
* You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
|
|
36
|
+
* @example
|
|
37
|
+
* ```cpp
|
|
38
|
+
* class HybridCactusIndex: public HybridCactusIndexSpec {
|
|
39
|
+
* public:
|
|
40
|
+
* HybridCactusIndex(...): HybridObject(TAG) { ... }
|
|
41
|
+
* // ...
|
|
42
|
+
* };
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
class HybridCactusIndexSpec: public virtual HybridObject {
|
|
46
|
+
public:
|
|
47
|
+
// Constructor
|
|
48
|
+
explicit HybridCactusIndexSpec(): HybridObject(TAG) { }
|
|
49
|
+
|
|
50
|
+
// Destructor
|
|
51
|
+
~HybridCactusIndexSpec() override = default;
|
|
52
|
+
|
|
53
|
+
public:
|
|
54
|
+
// Properties
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
public:
|
|
58
|
+
// Methods
|
|
59
|
+
virtual std::shared_ptr<Promise<void>> init(const std::string& indexPath, double embeddingDim) = 0;
|
|
60
|
+
virtual std::shared_ptr<Promise<void>> add(const std::vector<double>& ids, const std::vector<std::string>& documents, const std::vector<std::vector<double>>& embeddings, const std::optional<std::vector<std::string>>& metadatas) = 0;
|
|
61
|
+
virtual std::shared_ptr<Promise<void>> _delete(const std::vector<double>& ids) = 0;
|
|
62
|
+
virtual std::shared_ptr<Promise<CactusIndexGetResult>> get(const std::vector<double>& ids) = 0;
|
|
63
|
+
virtual std::shared_ptr<Promise<CactusIndexQueryResult>> query(const std::vector<std::vector<double>>& embeddings, const std::optional<std::string>& optionsJson) = 0;
|
|
64
|
+
virtual std::shared_ptr<Promise<void>> compact() = 0;
|
|
65
|
+
virtual std::shared_ptr<Promise<void>> destroy() = 0;
|
|
66
|
+
|
|
67
|
+
protected:
|
|
68
|
+
// Hybrid Setup
|
|
69
|
+
void loadHybridMethods() override;
|
|
70
|
+
|
|
71
|
+
protected:
|
|
72
|
+
// Tag for logging
|
|
73
|
+
static constexpr auto TAG = "CactusIndex";
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
} // namespace margelo::nitro::cactus
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// HybridCactusSpec.cpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#include "HybridCactusSpec.hpp"
|
|
@@ -16,7 +16,14 @@ namespace margelo::nitro::cactus {
|
|
|
16
16
|
registerHybrids(this, [](Prototype& prototype) {
|
|
17
17
|
prototype.registerHybridMethod("init", &HybridCactusSpec::init);
|
|
18
18
|
prototype.registerHybridMethod("complete", &HybridCactusSpec::complete);
|
|
19
|
+
prototype.registerHybridMethod("tokenize", &HybridCactusSpec::tokenize);
|
|
20
|
+
prototype.registerHybridMethod("scoreWindow", &HybridCactusSpec::scoreWindow);
|
|
19
21
|
prototype.registerHybridMethod("transcribe", &HybridCactusSpec::transcribe);
|
|
22
|
+
prototype.registerHybridMethod("streamTranscribeInit", &HybridCactusSpec::streamTranscribeInit);
|
|
23
|
+
prototype.registerHybridMethod("streamTranscribeInsert", &HybridCactusSpec::streamTranscribeInsert);
|
|
24
|
+
prototype.registerHybridMethod("streamTranscribeProcess", &HybridCactusSpec::streamTranscribeProcess);
|
|
25
|
+
prototype.registerHybridMethod("streamTranscribeFinalize", &HybridCactusSpec::streamTranscribeFinalize);
|
|
26
|
+
prototype.registerHybridMethod("streamTranscribeDestroy", &HybridCactusSpec::streamTranscribeDestroy);
|
|
20
27
|
prototype.registerHybridMethod("embed", &HybridCactusSpec::embed);
|
|
21
28
|
prototype.registerHybridMethod("imageEmbed", &HybridCactusSpec::imageEmbed);
|
|
22
29
|
prototype.registerHybridMethod("audioEmbed", &HybridCactusSpec::audioEmbed);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// HybridCactusSpec.hpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#pragma once
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
#include <optional>
|
|
21
21
|
#include <functional>
|
|
22
22
|
#include <vector>
|
|
23
|
+
#include <variant>
|
|
23
24
|
|
|
24
25
|
namespace margelo::nitro::cactus {
|
|
25
26
|
|
|
@@ -54,8 +55,15 @@ namespace margelo::nitro::cactus {
|
|
|
54
55
|
// Methods
|
|
55
56
|
virtual std::shared_ptr<Promise<void>> init(const std::string& modelPath, double contextSize, const std::optional<std::string>& corpusDir) = 0;
|
|
56
57
|
virtual std::shared_ptr<Promise<std::string>> complete(const std::string& messagesJson, double responseBufferSize, const std::optional<std::string>& optionsJson, const std::optional<std::string>& toolsJson, const std::optional<std::function<void(const std::string& /* token */, double /* tokenId */)>>& callback) = 0;
|
|
57
|
-
virtual std::shared_ptr<Promise<std::
|
|
58
|
-
virtual std::shared_ptr<Promise<std::
|
|
58
|
+
virtual std::shared_ptr<Promise<std::vector<double>>> tokenize(const std::string& text) = 0;
|
|
59
|
+
virtual std::shared_ptr<Promise<std::string>> scoreWindow(const std::vector<double>& tokens, double start, double end, double context) = 0;
|
|
60
|
+
virtual std::shared_ptr<Promise<std::string>> transcribe(const std::variant<std::vector<double>, std::string>& audio, const std::string& prompt, double responseBufferSize, const std::optional<std::string>& optionsJson, const std::optional<std::function<void(const std::string& /* token */, double /* tokenId */)>>& callback) = 0;
|
|
61
|
+
virtual std::shared_ptr<Promise<void>> streamTranscribeInit() = 0;
|
|
62
|
+
virtual std::shared_ptr<Promise<void>> streamTranscribeInsert(const std::vector<double>& audio) = 0;
|
|
63
|
+
virtual std::shared_ptr<Promise<std::string>> streamTranscribeProcess(const std::optional<std::string>& optionsJson) = 0;
|
|
64
|
+
virtual std::shared_ptr<Promise<std::string>> streamTranscribeFinalize() = 0;
|
|
65
|
+
virtual std::shared_ptr<Promise<void>> streamTranscribeDestroy() = 0;
|
|
66
|
+
virtual std::shared_ptr<Promise<std::vector<double>>> embed(const std::string& text, double embeddingBufferSize, bool normalize) = 0;
|
|
59
67
|
virtual std::shared_ptr<Promise<std::vector<double>>> imageEmbed(const std::string& imagePath, double embeddingBufferSize) = 0;
|
|
60
68
|
virtual std::shared_ptr<Promise<std::vector<double>>> audioEmbed(const std::string& audioPath, double embeddingBufferSize) = 0;
|
|
61
69
|
virtual std::shared_ptr<Promise<void>> reset() = 0;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// HybridCactusUtilSpec.cpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#include "HybridCactusUtilSpec.hpp"
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// HybridCactusUtilSpec.hpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#pragma once
|
|
@@ -51,7 +51,7 @@ namespace margelo::nitro::cactus {
|
|
|
51
51
|
public:
|
|
52
52
|
// Methods
|
|
53
53
|
virtual std::shared_ptr<Promise<std::string>> registerApp(const std::string& encryptedData) = 0;
|
|
54
|
-
virtual std::shared_ptr<Promise<std::optional<std::string>>> getDeviceId() = 0;
|
|
54
|
+
virtual std::shared_ptr<Promise<std::optional<std::string>>> getDeviceId(const std::optional<std::string>& token) = 0;
|
|
55
55
|
virtual std::shared_ptr<Promise<void>> setAndroidDataDirectory(const std::string& dataDir) = 0;
|
|
56
56
|
|
|
57
57
|
protected:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cactus-react-native",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Run AI models locally on mobile devices",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"react": "19.1.0",
|
|
84
84
|
"react-native": "0.81.1",
|
|
85
85
|
"react-native-builder-bob": "^0.40.14",
|
|
86
|
-
"react-native-nitro-modules": "^0.31.
|
|
86
|
+
"react-native-nitro-modules": "^0.31.10",
|
|
87
87
|
"release-it": "^19.0.4",
|
|
88
88
|
"turbo": "^2.5.6",
|
|
89
89
|
"typescript": "^5.9.2"
|
package/src/api/Database.ts
CHANGED
|
@@ -1,28 +1,7 @@
|
|
|
1
1
|
import { CactusUtil } from '../native';
|
|
2
2
|
import type { DeviceInfo } from '../specs/CactusDeviceInfo.nitro';
|
|
3
3
|
import type { LogRecord } from '../telemetry/Telemetry';
|
|
4
|
-
import {
|
|
5
|
-
import type { CactusModel } from '../types/CactusModel';
|
|
6
|
-
import type { CactusSTTModel } from '../types/CactusSTTModel';
|
|
7
|
-
|
|
8
|
-
interface CactusModelResponse {
|
|
9
|
-
name: string;
|
|
10
|
-
slug: string;
|
|
11
|
-
quantization: number;
|
|
12
|
-
size_mb: number;
|
|
13
|
-
download_url: string;
|
|
14
|
-
supports_tool_calling: boolean;
|
|
15
|
-
supports_vision: boolean;
|
|
16
|
-
supports_completion: boolean;
|
|
17
|
-
created_at: Date;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
interface CactusSTTModelResponse {
|
|
21
|
-
slug: string;
|
|
22
|
-
download_url: string;
|
|
23
|
-
size_mb: number;
|
|
24
|
-
created_at: Date;
|
|
25
|
-
}
|
|
4
|
+
import { CactusConfig } from '../config/CactusConfig';
|
|
26
5
|
|
|
27
6
|
export class Database {
|
|
28
7
|
private static readonly url = 'https://vlqqczxwyaodtcdmdmlw.supabase.co';
|
|
@@ -47,12 +26,23 @@ export class Database {
|
|
|
47
26
|
}
|
|
48
27
|
}
|
|
49
28
|
|
|
50
|
-
public static async registerDevice(
|
|
29
|
+
public static async registerDevice({
|
|
30
|
+
deviceData,
|
|
31
|
+
deviceId,
|
|
32
|
+
}: {
|
|
33
|
+
deviceData?: DeviceInfo;
|
|
34
|
+
deviceId?: string;
|
|
35
|
+
}): Promise<string> {
|
|
51
36
|
const response = await fetch(
|
|
52
37
|
`${this.url}/functions/v1/device-registration`,
|
|
53
38
|
{
|
|
54
39
|
method: 'POST',
|
|
55
|
-
body: JSON.stringify({
|
|
40
|
+
body: JSON.stringify({
|
|
41
|
+
device_data: deviceData,
|
|
42
|
+
device_id: deviceId,
|
|
43
|
+
cactus_pro_key: CactusConfig.cactusProKey,
|
|
44
|
+
}),
|
|
45
|
+
headers: { 'Content-Type': 'application/json' },
|
|
56
46
|
}
|
|
57
47
|
);
|
|
58
48
|
|
|
@@ -62,115 +52,4 @@ export class Database {
|
|
|
62
52
|
|
|
63
53
|
return await CactusUtil.registerApp(await response.text());
|
|
64
54
|
}
|
|
65
|
-
|
|
66
|
-
public static async getModel(slug: string): Promise<CactusModel> {
|
|
67
|
-
const response = await fetch(
|
|
68
|
-
`${this.url}/functions/v1/get-models?slug=${slug}&sdk_name=react&sdk_version=${packageVersion}`,
|
|
69
|
-
{
|
|
70
|
-
headers: { apikey: this.key, Authorization: `Bearer ${this.key}` },
|
|
71
|
-
}
|
|
72
|
-
);
|
|
73
|
-
|
|
74
|
-
if (!response.ok) {
|
|
75
|
-
throw new Error('Getting model failed');
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const model = (await response.json()) as CactusModelResponse;
|
|
79
|
-
|
|
80
|
-
return {
|
|
81
|
-
name: model.name,
|
|
82
|
-
slug: model.slug,
|
|
83
|
-
quantization: model.quantization,
|
|
84
|
-
sizeMb: model.size_mb,
|
|
85
|
-
downloadUrl: model.download_url,
|
|
86
|
-
supportsToolCalling: model.supports_tool_calling,
|
|
87
|
-
supportsVision: model.supports_vision,
|
|
88
|
-
supportsCompletion: model.supports_completion,
|
|
89
|
-
createdAt: model.created_at,
|
|
90
|
-
isDownloaded: false,
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
public static async getSTTModel(slug: string): Promise<CactusSTTModel> {
|
|
95
|
-
const response = await fetch(
|
|
96
|
-
`${this.url}/rest/v1/whisper?slug=eq.${slug}&select=*`,
|
|
97
|
-
{
|
|
98
|
-
headers: {
|
|
99
|
-
'apikey': this.key,
|
|
100
|
-
'Authorization': `Bearer ${this.key}`,
|
|
101
|
-
'Accept-Profile': 'cactus',
|
|
102
|
-
},
|
|
103
|
-
}
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
if (!response.ok) {
|
|
107
|
-
throw new Error('Getting STT model failed');
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const [model] = (await response.json()) as CactusSTTModelResponse[];
|
|
111
|
-
|
|
112
|
-
if (!model) {
|
|
113
|
-
throw new Error(`STT model with slug "${slug}" not found`);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
return {
|
|
117
|
-
slug: model.slug,
|
|
118
|
-
downloadUrl: model.download_url,
|
|
119
|
-
sizeMb: model.size_mb,
|
|
120
|
-
createdAt: model.created_at,
|
|
121
|
-
isDownloaded: false,
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
public static async getModels(): Promise<CactusModel[]> {
|
|
126
|
-
const response = await fetch(
|
|
127
|
-
`${this.url}/functions/v1/get-models?sdk_name=react&sdk_version=${packageVersion}`,
|
|
128
|
-
{
|
|
129
|
-
headers: { apikey: this.key, Authorization: `Bearer ${this.key}` },
|
|
130
|
-
}
|
|
131
|
-
);
|
|
132
|
-
|
|
133
|
-
if (!response.ok) {
|
|
134
|
-
throw new Error('Getting models failed');
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
const models = (await response.json()) as CactusModelResponse[];
|
|
138
|
-
|
|
139
|
-
return models.map((model) => ({
|
|
140
|
-
name: model.name,
|
|
141
|
-
slug: model.slug,
|
|
142
|
-
quantization: model.quantization,
|
|
143
|
-
sizeMb: model.size_mb,
|
|
144
|
-
downloadUrl: model.download_url,
|
|
145
|
-
supportsToolCalling: model.supports_tool_calling,
|
|
146
|
-
supportsVision: model.supports_vision,
|
|
147
|
-
supportsCompletion: model.supports_completion,
|
|
148
|
-
createdAt: model.created_at,
|
|
149
|
-
isDownloaded: false,
|
|
150
|
-
}));
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
public static async getSTTModels(): Promise<CactusSTTModel[]> {
|
|
154
|
-
const response = await fetch(`${this.url}/rest/v1/whisper?select=*`, {
|
|
155
|
-
headers: {
|
|
156
|
-
'apikey': this.key,
|
|
157
|
-
'Authorization': `Bearer ${this.key}`,
|
|
158
|
-
'Accept-Profile': 'cactus',
|
|
159
|
-
},
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
if (!response.ok) {
|
|
163
|
-
throw new Error('Getting STT models failed');
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
const models = (await response.json()) as CactusSTTModelResponse[];
|
|
167
|
-
|
|
168
|
-
return models.map((model) => ({
|
|
169
|
-
slug: model.slug,
|
|
170
|
-
downloadUrl: model.download_url,
|
|
171
|
-
sizeMb: model.size_mb,
|
|
172
|
-
createdAt: model.created_at,
|
|
173
|
-
isDownloaded: false,
|
|
174
|
-
}));
|
|
175
|
-
}
|
|
176
55
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { CactusIndex as NativeCactusIndex, CactusFileSystem } from '../native';
|
|
2
|
+
import type {
|
|
3
|
+
CactusIndexAddParams,
|
|
4
|
+
CactusIndexGetParams,
|
|
5
|
+
CactusIndexGetResult,
|
|
6
|
+
CactusIndexQueryParams,
|
|
7
|
+
CactusIndexQueryResult,
|
|
8
|
+
CactusIndexDeleteParams,
|
|
9
|
+
} from '../types/CactusIndex';
|
|
10
|
+
|
|
11
|
+
export class CactusIndex {
|
|
12
|
+
private readonly cactusIndex = new NativeCactusIndex();
|
|
13
|
+
|
|
14
|
+
private readonly name: string;
|
|
15
|
+
private readonly embeddingDim: number;
|
|
16
|
+
|
|
17
|
+
constructor(name: string, embeddingDim: number) {
|
|
18
|
+
this.name = name;
|
|
19
|
+
this.embeddingDim = embeddingDim;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public async init(): Promise<void> {
|
|
23
|
+
const indexPath = await CactusFileSystem.getIndexPath(this.name);
|
|
24
|
+
return this.cactusIndex.init(indexPath, this.embeddingDim);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public add({
|
|
28
|
+
ids,
|
|
29
|
+
documents,
|
|
30
|
+
embeddings,
|
|
31
|
+
metadatas,
|
|
32
|
+
}: CactusIndexAddParams): Promise<void> {
|
|
33
|
+
return this.cactusIndex.add(ids, documents, embeddings, metadatas);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public delete({ ids }: CactusIndexDeleteParams): Promise<void> {
|
|
37
|
+
return this.cactusIndex.delete(ids);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public get({ ids }: CactusIndexGetParams): Promise<CactusIndexGetResult> {
|
|
41
|
+
return this.cactusIndex.get(ids);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public query({
|
|
45
|
+
embeddings,
|
|
46
|
+
options,
|
|
47
|
+
}: CactusIndexQueryParams): Promise<CactusIndexQueryResult> {
|
|
48
|
+
return this.cactusIndex.query(embeddings, options);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public compact(): Promise<void> {
|
|
52
|
+
return this.cactusIndex.compact();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public destroy(): Promise<void> {
|
|
56
|
+
return this.cactusIndex.destroy();
|
|
57
|
+
}
|
|
58
|
+
}
|