cactus-react-native 1.4.0 → 1.7.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/Cactus.podspec +1 -1
- package/README.md +465 -174
- package/android/CMakeLists.txt +24 -5
- package/android/src/main/jniLibs/arm64-v8a/libcactus.a +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libcurl.a +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libmbedcrypto.a +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libmbedtls.a +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libmbedx509.a +0 -0
- package/cpp/HybridCactus.cpp +157 -6
- package/cpp/HybridCactus.hpp +20 -3
- package/cpp/cactus_ffi.h +65 -30
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/cactus.h +0 -1
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/cactus_ffi.h +65 -30
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/cactus_utils.h +357 -122
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/engine.h +184 -63
- 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 +153 -27
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/kernel.h +90 -178
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/kernel_utils.h +276 -151
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/cactus +0 -0
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/cactus.h +0 -1
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/cactus_ffi.h +65 -30
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/cactus_utils.h +357 -122
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/engine.h +184 -63
- 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 +153 -27
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/kernel.h +90 -178
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/kernel_utils.h +276 -151
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/cactus +0 -0
- package/lib/module/classes/CactusLM.js +43 -58
- package/lib/module/classes/CactusLM.js.map +1 -1
- package/lib/module/classes/CactusSTT.js +64 -38
- package/lib/module/classes/CactusSTT.js.map +1 -1
- package/lib/module/classes/CactusVAD.js +95 -0
- package/lib/module/classes/CactusVAD.js.map +1 -0
- package/lib/module/hooks/useCactusLM.js +23 -15
- package/lib/module/hooks/useCactusLM.js.map +1 -1
- package/lib/module/hooks/useCactusSTT.js +85 -28
- package/lib/module/hooks/useCactusSTT.js.map +1 -1
- package/lib/module/hooks/useCactusVAD.js +171 -0
- package/lib/module/hooks/useCactusVAD.js.map +1 -0
- package/lib/module/index.js +2 -3
- package/lib/module/index.js.map +1 -1
- package/lib/module/modelRegistry.js +52 -0
- package/lib/module/modelRegistry.js.map +1 -0
- package/lib/module/native/Cactus.js +107 -8
- package/lib/module/native/Cactus.js.map +1 -1
- package/lib/module/native/CactusIndex.js.map +1 -1
- package/lib/module/native/index.js +0 -3
- package/lib/module/native/index.js.map +1 -1
- package/lib/module/types/CactusLM.js +2 -0
- package/lib/module/types/CactusSTT.js +2 -0
- package/lib/module/types/CactusVAD.js +4 -0
- package/lib/module/types/{CactusModel.js.map → CactusVAD.js.map} +1 -1
- package/lib/module/types/common.js +2 -0
- package/lib/module/types/{CactusSTTModel.js.map → common.js.map} +1 -1
- package/lib/typescript/src/classes/CactusLM.d.ts +8 -6
- package/lib/typescript/src/classes/CactusLM.d.ts.map +1 -1
- package/lib/typescript/src/classes/CactusSTT.d.ts +11 -6
- package/lib/typescript/src/classes/CactusSTT.d.ts.map +1 -1
- package/lib/typescript/src/classes/CactusVAD.d.ts +20 -0
- package/lib/typescript/src/classes/CactusVAD.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useCactusLM.d.ts +3 -3
- package/lib/typescript/src/hooks/useCactusLM.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useCactusSTT.d.ts +11 -5
- package/lib/typescript/src/hooks/useCactusSTT.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useCactusVAD.d.ts +15 -0
- package/lib/typescript/src/hooks/useCactusVAD.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +7 -6
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/modelRegistry.d.ts +5 -0
- package/lib/typescript/src/modelRegistry.d.ts.map +1 -0
- package/lib/typescript/src/native/Cactus.d.ts +12 -6
- package/lib/typescript/src/native/Cactus.d.ts.map +1 -1
- package/lib/typescript/src/native/CactusIndex.d.ts +2 -2
- package/lib/typescript/src/native/CactusIndex.d.ts.map +1 -1
- package/lib/typescript/src/native/index.d.ts +0 -3
- package/lib/typescript/src/native/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/Cactus.nitro.d.ts +6 -1
- package/lib/typescript/src/specs/Cactus.nitro.d.ts.map +1 -1
- package/lib/typescript/src/types/CactusIndex.d.ts +2 -2
- package/lib/typescript/src/types/CactusIndex.d.ts.map +1 -1
- package/lib/typescript/src/types/CactusLM.d.ts +19 -9
- package/lib/typescript/src/types/CactusLM.d.ts.map +1 -1
- package/lib/typescript/src/types/CactusSTT.d.ts +45 -4
- package/lib/typescript/src/types/CactusSTT.d.ts.map +1 -1
- package/lib/typescript/src/types/CactusVAD.d.ts +34 -0
- package/lib/typescript/src/types/CactusVAD.d.ts.map +1 -0
- package/lib/typescript/src/types/common.d.ts +23 -0
- package/lib/typescript/src/types/common.d.ts.map +1 -0
- package/nitro.json +0 -11
- package/nitrogen/generated/android/cactus+autolinking.cmake +0 -5
- package/nitrogen/generated/android/cactusOnLoad.cpp +0 -30
- package/nitrogen/generated/ios/Cactus-Swift-Cxx-Bridge.cpp +0 -50
- package/nitrogen/generated/ios/Cactus-Swift-Cxx-Bridge.hpp +9 -147
- package/nitrogen/generated/ios/Cactus-Swift-Cxx-Umbrella.hpp +0 -13
- package/nitrogen/generated/ios/CactusAutolinking.mm +0 -26
- package/nitrogen/generated/ios/CactusAutolinking.swift +0 -30
- package/nitrogen/generated/shared/c++/HybridCactusSpec.cpp +5 -0
- package/nitrogen/generated/shared/c++/HybridCactusSpec.hpp +6 -1
- package/package.json +3 -3
- package/src/classes/CactusLM.ts +59 -74
- package/src/classes/CactusSTT.ts +92 -49
- package/src/classes/CactusVAD.ts +129 -0
- package/src/hooks/useCactusLM.ts +26 -9
- package/src/hooks/useCactusSTT.ts +105 -44
- package/src/hooks/useCactusVAD.ts +215 -0
- package/src/index.tsx +20 -10
- package/src/modelRegistry.ts +65 -0
- package/src/native/Cactus.ts +130 -14
- package/src/native/CactusIndex.ts +2 -2
- package/src/native/index.ts +0 -3
- package/src/specs/Cactus.nitro.ts +11 -2
- package/src/types/CactusIndex.ts +2 -2
- package/src/types/CactusLM.ts +20 -9
- package/src/types/CactusSTT.ts +50 -4
- package/src/types/CactusVAD.ts +39 -0
- package/src/types/common.ts +23 -0
- package/android/src/main/java/com/margelo/nitro/cactus/HybridCactusCrypto.kt +0 -46
- package/android/src/main/java/com/margelo/nitro/cactus/HybridCactusDeviceInfo.kt +0 -27
- package/android/src/main/jniLibs/arm64-v8a/libcactus_util.a +0 -0
- package/cpp/HybridCactusUtil.cpp +0 -47
- package/cpp/HybridCactusUtil.hpp +0 -27
- package/cpp/cactus_util.h +0 -25
- package/ios/HybridCactusCrypto.swift +0 -37
- package/ios/HybridCactusDeviceInfo.swift +0 -32
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/cactus_telemetry.h +0 -656
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/cactus_telemetry.h +0 -656
- package/ios/cactus_util.xcframework/Info.plist +0 -39
- package/ios/cactus_util.xcframework/ios-arm64/cactus_util.framework/Headers/cactus_util.h +0 -25
- package/ios/cactus_util.xcframework/ios-arm64/cactus_util.framework/Headers/database.h +0 -27
- package/ios/cactus_util.xcframework/ios-arm64/cactus_util.framework/Headers/ios_utils.h +0 -10
- package/ios/cactus_util.xcframework/ios-arm64/cactus_util.framework/Headers/logging.h +0 -25
- 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 +0 -25
- package/ios/cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework/Headers/database.h +0 -27
- package/ios/cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework/Headers/ios_utils.h +0 -10
- package/ios/cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework/Headers/logging.h +0 -25
- 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 +0 -135
- package/ios/cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework/cactus_util +0 -0
- package/lib/module/api/Database.js +0 -137
- package/lib/module/api/Database.js.map +0 -1
- package/lib/module/api/RemoteLM.js +0 -201
- package/lib/module/api/RemoteLM.js.map +0 -1
- package/lib/module/config/CactusConfig.js +0 -12
- package/lib/module/config/CactusConfig.js.map +0 -1
- package/lib/module/native/CactusCrypto.js +0 -10
- package/lib/module/native/CactusCrypto.js.map +0 -1
- package/lib/module/native/CactusDeviceInfo.js +0 -13
- package/lib/module/native/CactusDeviceInfo.js.map +0 -1
- package/lib/module/native/CactusUtil.js +0 -36
- package/lib/module/native/CactusUtil.js.map +0 -1
- package/lib/module/specs/CactusCrypto.nitro.js +0 -4
- package/lib/module/specs/CactusCrypto.nitro.js.map +0 -1
- package/lib/module/specs/CactusDeviceInfo.nitro.js +0 -4
- package/lib/module/specs/CactusDeviceInfo.nitro.js.map +0 -1
- package/lib/module/specs/CactusUtil.nitro.js +0 -4
- package/lib/module/specs/CactusUtil.nitro.js.map +0 -1
- package/lib/module/telemetry/Telemetry.js +0 -154
- package/lib/module/telemetry/Telemetry.js.map +0 -1
- package/lib/module/types/CactusModel.js +0 -2
- package/lib/module/types/CactusSTTModel.js +0 -2
- package/lib/typescript/src/api/Database.d.ts +0 -18
- package/lib/typescript/src/api/Database.d.ts.map +0 -1
- package/lib/typescript/src/api/RemoteLM.d.ts +0 -14
- package/lib/typescript/src/api/RemoteLM.d.ts.map +0 -1
- package/lib/typescript/src/config/CactusConfig.d.ts +0 -7
- package/lib/typescript/src/config/CactusConfig.d.ts.map +0 -1
- package/lib/typescript/src/native/CactusCrypto.d.ts +0 -5
- package/lib/typescript/src/native/CactusCrypto.d.ts.map +0 -1
- package/lib/typescript/src/native/CactusDeviceInfo.d.ts +0 -7
- package/lib/typescript/src/native/CactusDeviceInfo.d.ts.map +0 -1
- package/lib/typescript/src/native/CactusUtil.d.ts +0 -6
- package/lib/typescript/src/native/CactusUtil.d.ts.map +0 -1
- package/lib/typescript/src/specs/CactusCrypto.nitro.d.ts +0 -8
- package/lib/typescript/src/specs/CactusCrypto.nitro.d.ts.map +0 -1
- package/lib/typescript/src/specs/CactusDeviceInfo.nitro.d.ts +0 -16
- package/lib/typescript/src/specs/CactusDeviceInfo.nitro.d.ts.map +0 -1
- package/lib/typescript/src/specs/CactusUtil.nitro.d.ts +0 -10
- package/lib/typescript/src/specs/CactusUtil.nitro.d.ts.map +0 -1
- package/lib/typescript/src/telemetry/Telemetry.d.ts +0 -34
- package/lib/typescript/src/telemetry/Telemetry.d.ts.map +0 -1
- 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/nitrogen/generated/android/c++/JDeviceInfo.hpp +0 -74
- package/nitrogen/generated/android/c++/JHybridCactusCryptoSpec.cpp +0 -65
- package/nitrogen/generated/android/c++/JHybridCactusCryptoSpec.hpp +0 -65
- package/nitrogen/generated/android/c++/JHybridCactusDeviceInfoSpec.cpp +0 -85
- package/nitrogen/generated/android/c++/JHybridCactusDeviceInfoSpec.hpp +0 -66
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/DeviceInfo.kt +0 -50
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/HybridCactusCryptoSpec.kt +0 -58
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/HybridCactusDeviceInfoSpec.kt +0 -62
- package/nitrogen/generated/ios/c++/HybridCactusCryptoSpecSwift.cpp +0 -11
- package/nitrogen/generated/ios/c++/HybridCactusCryptoSpecSwift.hpp +0 -77
- package/nitrogen/generated/ios/c++/HybridCactusDeviceInfoSpecSwift.cpp +0 -11
- package/nitrogen/generated/ios/c++/HybridCactusDeviceInfoSpecSwift.hpp +0 -88
- package/nitrogen/generated/ios/swift/DeviceInfo.swift +0 -98
- package/nitrogen/generated/ios/swift/Func_void_DeviceInfo.swift +0 -47
- package/nitrogen/generated/ios/swift/Func_void_std__optional_std__string_.swift +0 -54
- package/nitrogen/generated/ios/swift/HybridCactusCryptoSpec.swift +0 -57
- package/nitrogen/generated/ios/swift/HybridCactusCryptoSpec_cxx.swift +0 -139
- package/nitrogen/generated/ios/swift/HybridCactusDeviceInfoSpec.swift +0 -58
- package/nitrogen/generated/ios/swift/HybridCactusDeviceInfoSpec_cxx.swift +0 -164
- package/nitrogen/generated/shared/c++/DeviceInfo.hpp +0 -92
- package/nitrogen/generated/shared/c++/HybridCactusCryptoSpec.cpp +0 -21
- package/nitrogen/generated/shared/c++/HybridCactusCryptoSpec.hpp +0 -63
- package/nitrogen/generated/shared/c++/HybridCactusDeviceInfoSpec.cpp +0 -22
- package/nitrogen/generated/shared/c++/HybridCactusDeviceInfoSpec.hpp +0 -67
- package/nitrogen/generated/shared/c++/HybridCactusUtilSpec.cpp +0 -23
- package/nitrogen/generated/shared/c++/HybridCactusUtilSpec.hpp +0 -66
- package/src/api/Database.ts +0 -188
- package/src/api/RemoteLM.ts +0 -273
- package/src/config/CactusConfig.ts +0 -11
- package/src/native/CactusCrypto.ts +0 -11
- package/src/native/CactusDeviceInfo.ts +0 -18
- package/src/native/CactusUtil.ts +0 -43
- package/src/specs/CactusCrypto.nitro.ts +0 -6
- package/src/specs/CactusDeviceInfo.nitro.ts +0 -15
- package/src/specs/CactusUtil.nitro.ts +0 -8
- package/src/telemetry/Telemetry.ts +0 -236
- package/src/types/CactusModel.ts +0 -15
- package/src/types/CactusSTTModel.ts +0 -10
|
@@ -8,31 +8,18 @@
|
|
|
8
8
|
#pragma once
|
|
9
9
|
|
|
10
10
|
// Forward declarations of C++ defined types
|
|
11
|
-
// Forward declaration of `DeviceInfo` to properly resolve imports.
|
|
12
|
-
namespace margelo::nitro::cactus { struct DeviceInfo; }
|
|
13
|
-
// Forward declaration of `HybridCactusCryptoSpec` to properly resolve imports.
|
|
14
|
-
namespace margelo::nitro::cactus { class HybridCactusCryptoSpec; }
|
|
15
|
-
// Forward declaration of `HybridCactusDeviceInfoSpec` to properly resolve imports.
|
|
16
|
-
namespace margelo::nitro::cactus { class HybridCactusDeviceInfoSpec; }
|
|
17
11
|
// Forward declaration of `HybridCactusFileSystemSpec` to properly resolve imports.
|
|
18
12
|
namespace margelo::nitro::cactus { class HybridCactusFileSystemSpec; }
|
|
19
13
|
// Forward declaration of `HybridCactusImageSpec` to properly resolve imports.
|
|
20
14
|
namespace margelo::nitro::cactus { class HybridCactusImageSpec; }
|
|
21
15
|
|
|
22
16
|
// Forward declarations of Swift defined types
|
|
23
|
-
// Forward declaration of `HybridCactusCryptoSpec_cxx` to properly resolve imports.
|
|
24
|
-
namespace Cactus { class HybridCactusCryptoSpec_cxx; }
|
|
25
|
-
// Forward declaration of `HybridCactusDeviceInfoSpec_cxx` to properly resolve imports.
|
|
26
|
-
namespace Cactus { class HybridCactusDeviceInfoSpec_cxx; }
|
|
27
17
|
// Forward declaration of `HybridCactusFileSystemSpec_cxx` to properly resolve imports.
|
|
28
18
|
namespace Cactus { class HybridCactusFileSystemSpec_cxx; }
|
|
29
19
|
// Forward declaration of `HybridCactusImageSpec_cxx` to properly resolve imports.
|
|
30
20
|
namespace Cactus { class HybridCactusImageSpec_cxx; }
|
|
31
21
|
|
|
32
22
|
// Include C++ defined types
|
|
33
|
-
#include "DeviceInfo.hpp"
|
|
34
|
-
#include "HybridCactusCryptoSpec.hpp"
|
|
35
|
-
#include "HybridCactusDeviceInfoSpec.hpp"
|
|
36
23
|
#include "HybridCactusFileSystemSpec.hpp"
|
|
37
24
|
#include "HybridCactusImageSpec.hpp"
|
|
38
25
|
#include <NitroModules/Promise.hpp>
|
|
@@ -106,140 +93,6 @@ namespace margelo::nitro::cactus::bridge::swift {
|
|
|
106
93
|
return Func_void_std__exception_ptr_Wrapper(std::move(value));
|
|
107
94
|
}
|
|
108
95
|
|
|
109
|
-
// pragma MARK: std::shared_ptr<HybridCactusCryptoSpec>
|
|
110
|
-
/**
|
|
111
|
-
* Specialized version of `std::shared_ptr<HybridCactusCryptoSpec>`.
|
|
112
|
-
*/
|
|
113
|
-
using std__shared_ptr_HybridCactusCryptoSpec_ = std::shared_ptr<HybridCactusCryptoSpec>;
|
|
114
|
-
std::shared_ptr<HybridCactusCryptoSpec> create_std__shared_ptr_HybridCactusCryptoSpec_(void* NON_NULL swiftUnsafePointer) noexcept;
|
|
115
|
-
void* NON_NULL get_std__shared_ptr_HybridCactusCryptoSpec_(std__shared_ptr_HybridCactusCryptoSpec_ cppType);
|
|
116
|
-
|
|
117
|
-
// pragma MARK: std::weak_ptr<HybridCactusCryptoSpec>
|
|
118
|
-
using std__weak_ptr_HybridCactusCryptoSpec_ = std::weak_ptr<HybridCactusCryptoSpec>;
|
|
119
|
-
inline std__weak_ptr_HybridCactusCryptoSpec_ weakify_std__shared_ptr_HybridCactusCryptoSpec_(const std::shared_ptr<HybridCactusCryptoSpec>& strong) noexcept { return strong; }
|
|
120
|
-
|
|
121
|
-
// pragma MARK: Result<std::shared_ptr<Promise<std::string>>>
|
|
122
|
-
using Result_std__shared_ptr_Promise_std__string___ = Result<std::shared_ptr<Promise<std::string>>>;
|
|
123
|
-
inline Result_std__shared_ptr_Promise_std__string___ create_Result_std__shared_ptr_Promise_std__string___(const std::shared_ptr<Promise<std::string>>& value) noexcept {
|
|
124
|
-
return Result<std::shared_ptr<Promise<std::string>>>::withValue(value);
|
|
125
|
-
}
|
|
126
|
-
inline Result_std__shared_ptr_Promise_std__string___ create_Result_std__shared_ptr_Promise_std__string___(const std::exception_ptr& error) noexcept {
|
|
127
|
-
return Result<std::shared_ptr<Promise<std::string>>>::withError(error);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// pragma MARK: std::optional<std::string>
|
|
131
|
-
/**
|
|
132
|
-
* Specialized version of `std::optional<std::string>`.
|
|
133
|
-
*/
|
|
134
|
-
using std__optional_std__string_ = std::optional<std::string>;
|
|
135
|
-
inline std::optional<std::string> create_std__optional_std__string_(const std::string& value) noexcept {
|
|
136
|
-
return std::optional<std::string>(value);
|
|
137
|
-
}
|
|
138
|
-
inline bool has_value_std__optional_std__string_(const std::optional<std::string>& optional) noexcept {
|
|
139
|
-
return optional.has_value();
|
|
140
|
-
}
|
|
141
|
-
inline std::string get_std__optional_std__string_(const std::optional<std::string>& optional) noexcept {
|
|
142
|
-
return *optional;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// pragma MARK: std::shared_ptr<Promise<std::optional<std::string>>>
|
|
146
|
-
/**
|
|
147
|
-
* Specialized version of `std::shared_ptr<Promise<std::optional<std::string>>>`.
|
|
148
|
-
*/
|
|
149
|
-
using std__shared_ptr_Promise_std__optional_std__string___ = std::shared_ptr<Promise<std::optional<std::string>>>;
|
|
150
|
-
inline std::shared_ptr<Promise<std::optional<std::string>>> create_std__shared_ptr_Promise_std__optional_std__string___() noexcept {
|
|
151
|
-
return Promise<std::optional<std::string>>::create();
|
|
152
|
-
}
|
|
153
|
-
inline PromiseHolder<std::optional<std::string>> wrap_std__shared_ptr_Promise_std__optional_std__string___(std::shared_ptr<Promise<std::optional<std::string>>> promise) noexcept {
|
|
154
|
-
return PromiseHolder<std::optional<std::string>>(std::move(promise));
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// pragma MARK: std::function<void(const std::optional<std::string>& /* result */)>
|
|
158
|
-
/**
|
|
159
|
-
* Specialized version of `std::function<void(const std::optional<std::string>&)>`.
|
|
160
|
-
*/
|
|
161
|
-
using Func_void_std__optional_std__string_ = std::function<void(const std::optional<std::string>& /* result */)>;
|
|
162
|
-
/**
|
|
163
|
-
* Wrapper class for a `std::function<void(const std::optional<std::string>& / * result * /)>`, this can be used from Swift.
|
|
164
|
-
*/
|
|
165
|
-
class Func_void_std__optional_std__string__Wrapper final {
|
|
166
|
-
public:
|
|
167
|
-
explicit Func_void_std__optional_std__string__Wrapper(std::function<void(const std::optional<std::string>& /* result */)>&& func): _function(std::make_unique<std::function<void(const std::optional<std::string>& /* result */)>>(std::move(func))) {}
|
|
168
|
-
inline void call(std::optional<std::string> result) const noexcept {
|
|
169
|
-
_function->operator()(result);
|
|
170
|
-
}
|
|
171
|
-
private:
|
|
172
|
-
std::unique_ptr<std::function<void(const std::optional<std::string>& /* result */)>> _function;
|
|
173
|
-
} SWIFT_NONCOPYABLE;
|
|
174
|
-
Func_void_std__optional_std__string_ create_Func_void_std__optional_std__string_(void* NON_NULL swiftClosureWrapper) noexcept;
|
|
175
|
-
inline Func_void_std__optional_std__string__Wrapper wrap_Func_void_std__optional_std__string_(Func_void_std__optional_std__string_ value) noexcept {
|
|
176
|
-
return Func_void_std__optional_std__string__Wrapper(std::move(value));
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
// pragma MARK: std::shared_ptr<Promise<DeviceInfo>>
|
|
180
|
-
/**
|
|
181
|
-
* Specialized version of `std::shared_ptr<Promise<DeviceInfo>>`.
|
|
182
|
-
*/
|
|
183
|
-
using std__shared_ptr_Promise_DeviceInfo__ = std::shared_ptr<Promise<DeviceInfo>>;
|
|
184
|
-
inline std::shared_ptr<Promise<DeviceInfo>> create_std__shared_ptr_Promise_DeviceInfo__() noexcept {
|
|
185
|
-
return Promise<DeviceInfo>::create();
|
|
186
|
-
}
|
|
187
|
-
inline PromiseHolder<DeviceInfo> wrap_std__shared_ptr_Promise_DeviceInfo__(std::shared_ptr<Promise<DeviceInfo>> promise) noexcept {
|
|
188
|
-
return PromiseHolder<DeviceInfo>(std::move(promise));
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
// pragma MARK: std::function<void(const DeviceInfo& /* result */)>
|
|
192
|
-
/**
|
|
193
|
-
* Specialized version of `std::function<void(const DeviceInfo&)>`.
|
|
194
|
-
*/
|
|
195
|
-
using Func_void_DeviceInfo = std::function<void(const DeviceInfo& /* result */)>;
|
|
196
|
-
/**
|
|
197
|
-
* Wrapper class for a `std::function<void(const DeviceInfo& / * result * /)>`, this can be used from Swift.
|
|
198
|
-
*/
|
|
199
|
-
class Func_void_DeviceInfo_Wrapper final {
|
|
200
|
-
public:
|
|
201
|
-
explicit Func_void_DeviceInfo_Wrapper(std::function<void(const DeviceInfo& /* result */)>&& func): _function(std::make_unique<std::function<void(const DeviceInfo& /* result */)>>(std::move(func))) {}
|
|
202
|
-
inline void call(DeviceInfo result) const noexcept {
|
|
203
|
-
_function->operator()(result);
|
|
204
|
-
}
|
|
205
|
-
private:
|
|
206
|
-
std::unique_ptr<std::function<void(const DeviceInfo& /* result */)>> _function;
|
|
207
|
-
} SWIFT_NONCOPYABLE;
|
|
208
|
-
Func_void_DeviceInfo create_Func_void_DeviceInfo(void* NON_NULL swiftClosureWrapper) noexcept;
|
|
209
|
-
inline Func_void_DeviceInfo_Wrapper wrap_Func_void_DeviceInfo(Func_void_DeviceInfo value) noexcept {
|
|
210
|
-
return Func_void_DeviceInfo_Wrapper(std::move(value));
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// pragma MARK: std::shared_ptr<HybridCactusDeviceInfoSpec>
|
|
214
|
-
/**
|
|
215
|
-
* Specialized version of `std::shared_ptr<HybridCactusDeviceInfoSpec>`.
|
|
216
|
-
*/
|
|
217
|
-
using std__shared_ptr_HybridCactusDeviceInfoSpec_ = std::shared_ptr<HybridCactusDeviceInfoSpec>;
|
|
218
|
-
std::shared_ptr<HybridCactusDeviceInfoSpec> create_std__shared_ptr_HybridCactusDeviceInfoSpec_(void* NON_NULL swiftUnsafePointer) noexcept;
|
|
219
|
-
void* NON_NULL get_std__shared_ptr_HybridCactusDeviceInfoSpec_(std__shared_ptr_HybridCactusDeviceInfoSpec_ cppType);
|
|
220
|
-
|
|
221
|
-
// pragma MARK: std::weak_ptr<HybridCactusDeviceInfoSpec>
|
|
222
|
-
using std__weak_ptr_HybridCactusDeviceInfoSpec_ = std::weak_ptr<HybridCactusDeviceInfoSpec>;
|
|
223
|
-
inline std__weak_ptr_HybridCactusDeviceInfoSpec_ weakify_std__shared_ptr_HybridCactusDeviceInfoSpec_(const std::shared_ptr<HybridCactusDeviceInfoSpec>& strong) noexcept { return strong; }
|
|
224
|
-
|
|
225
|
-
// pragma MARK: Result<std::shared_ptr<Promise<std::optional<std::string>>>>
|
|
226
|
-
using Result_std__shared_ptr_Promise_std__optional_std__string____ = Result<std::shared_ptr<Promise<std::optional<std::string>>>>;
|
|
227
|
-
inline Result_std__shared_ptr_Promise_std__optional_std__string____ create_Result_std__shared_ptr_Promise_std__optional_std__string____(const std::shared_ptr<Promise<std::optional<std::string>>>& value) noexcept {
|
|
228
|
-
return Result<std::shared_ptr<Promise<std::optional<std::string>>>>::withValue(value);
|
|
229
|
-
}
|
|
230
|
-
inline Result_std__shared_ptr_Promise_std__optional_std__string____ create_Result_std__shared_ptr_Promise_std__optional_std__string____(const std::exception_ptr& error) noexcept {
|
|
231
|
-
return Result<std::shared_ptr<Promise<std::optional<std::string>>>>::withError(error);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
// pragma MARK: Result<std::shared_ptr<Promise<DeviceInfo>>>
|
|
235
|
-
using Result_std__shared_ptr_Promise_DeviceInfo___ = Result<std::shared_ptr<Promise<DeviceInfo>>>;
|
|
236
|
-
inline Result_std__shared_ptr_Promise_DeviceInfo___ create_Result_std__shared_ptr_Promise_DeviceInfo___(const std::shared_ptr<Promise<DeviceInfo>>& value) noexcept {
|
|
237
|
-
return Result<std::shared_ptr<Promise<DeviceInfo>>>::withValue(value);
|
|
238
|
-
}
|
|
239
|
-
inline Result_std__shared_ptr_Promise_DeviceInfo___ create_Result_std__shared_ptr_Promise_DeviceInfo___(const std::exception_ptr& error) noexcept {
|
|
240
|
-
return Result<std::shared_ptr<Promise<DeviceInfo>>>::withError(error);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
96
|
// pragma MARK: std::shared_ptr<Promise<bool>>
|
|
244
97
|
/**
|
|
245
98
|
* Specialized version of `std::shared_ptr<Promise<bool>>`.
|
|
@@ -357,6 +210,15 @@ namespace margelo::nitro::cactus::bridge::swift {
|
|
|
357
210
|
using std__weak_ptr_HybridCactusFileSystemSpec_ = std::weak_ptr<HybridCactusFileSystemSpec>;
|
|
358
211
|
inline std__weak_ptr_HybridCactusFileSystemSpec_ weakify_std__shared_ptr_HybridCactusFileSystemSpec_(const std::shared_ptr<HybridCactusFileSystemSpec>& strong) noexcept { return strong; }
|
|
359
212
|
|
|
213
|
+
// pragma MARK: Result<std::shared_ptr<Promise<std::string>>>
|
|
214
|
+
using Result_std__shared_ptr_Promise_std__string___ = Result<std::shared_ptr<Promise<std::string>>>;
|
|
215
|
+
inline Result_std__shared_ptr_Promise_std__string___ create_Result_std__shared_ptr_Promise_std__string___(const std::shared_ptr<Promise<std::string>>& value) noexcept {
|
|
216
|
+
return Result<std::shared_ptr<Promise<std::string>>>::withValue(value);
|
|
217
|
+
}
|
|
218
|
+
inline Result_std__shared_ptr_Promise_std__string___ create_Result_std__shared_ptr_Promise_std__string___(const std::exception_ptr& error) noexcept {
|
|
219
|
+
return Result<std::shared_ptr<Promise<std::string>>>::withError(error);
|
|
220
|
+
}
|
|
221
|
+
|
|
360
222
|
// pragma MARK: Result<std::shared_ptr<Promise<bool>>>
|
|
361
223
|
using Result_std__shared_ptr_Promise_bool___ = Result<std::shared_ptr<Promise<bool>>>;
|
|
362
224
|
inline Result_std__shared_ptr_Promise_bool___ create_Result_std__shared_ptr_Promise_bool___(const std::shared_ptr<Promise<bool>>& value) noexcept {
|
|
@@ -8,21 +8,12 @@
|
|
|
8
8
|
#pragma once
|
|
9
9
|
|
|
10
10
|
// Forward declarations of C++ defined types
|
|
11
|
-
// Forward declaration of `DeviceInfo` to properly resolve imports.
|
|
12
|
-
namespace margelo::nitro::cactus { struct DeviceInfo; }
|
|
13
|
-
// Forward declaration of `HybridCactusCryptoSpec` to properly resolve imports.
|
|
14
|
-
namespace margelo::nitro::cactus { class HybridCactusCryptoSpec; }
|
|
15
|
-
// Forward declaration of `HybridCactusDeviceInfoSpec` to properly resolve imports.
|
|
16
|
-
namespace margelo::nitro::cactus { class HybridCactusDeviceInfoSpec; }
|
|
17
11
|
// Forward declaration of `HybridCactusFileSystemSpec` to properly resolve imports.
|
|
18
12
|
namespace margelo::nitro::cactus { class HybridCactusFileSystemSpec; }
|
|
19
13
|
// Forward declaration of `HybridCactusImageSpec` to properly resolve imports.
|
|
20
14
|
namespace margelo::nitro::cactus { class HybridCactusImageSpec; }
|
|
21
15
|
|
|
22
16
|
// Include C++ defined types
|
|
23
|
-
#include "DeviceInfo.hpp"
|
|
24
|
-
#include "HybridCactusCryptoSpec.hpp"
|
|
25
|
-
#include "HybridCactusDeviceInfoSpec.hpp"
|
|
26
17
|
#include "HybridCactusFileSystemSpec.hpp"
|
|
27
18
|
#include "HybridCactusImageSpec.hpp"
|
|
28
19
|
#include <NitroModules/Promise.hpp>
|
|
@@ -43,10 +34,6 @@ namespace margelo::nitro::cactus { class HybridCactusImageSpec; }
|
|
|
43
34
|
#include <NitroModules/DateToChronoDate.hpp>
|
|
44
35
|
|
|
45
36
|
// Forward declarations of Swift defined types
|
|
46
|
-
// Forward declaration of `HybridCactusCryptoSpec_cxx` to properly resolve imports.
|
|
47
|
-
namespace Cactus { class HybridCactusCryptoSpec_cxx; }
|
|
48
|
-
// Forward declaration of `HybridCactusDeviceInfoSpec_cxx` to properly resolve imports.
|
|
49
|
-
namespace Cactus { class HybridCactusDeviceInfoSpec_cxx; }
|
|
50
37
|
// Forward declaration of `HybridCactusFileSystemSpec_cxx` to properly resolve imports.
|
|
51
38
|
namespace Cactus { class HybridCactusFileSystemSpec_cxx; }
|
|
52
39
|
// Forward declaration of `HybridCactusImageSpec_cxx` to properly resolve imports.
|
|
@@ -12,10 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
#include "HybridCactus.hpp"
|
|
14
14
|
#include "HybridCactusIndex.hpp"
|
|
15
|
-
#include "HybridCactusUtil.hpp"
|
|
16
15
|
#include "HybridCactusFileSystemSpecSwift.hpp"
|
|
17
|
-
#include "HybridCactusCryptoSpecSwift.hpp"
|
|
18
|
-
#include "HybridCactusDeviceInfoSpecSwift.hpp"
|
|
19
16
|
#include "HybridCactusImageSpecSwift.hpp"
|
|
20
17
|
|
|
21
18
|
@interface CactusAutolinking : NSObject
|
|
@@ -45,15 +42,6 @@
|
|
|
45
42
|
return std::make_shared<HybridCactusIndex>();
|
|
46
43
|
}
|
|
47
44
|
);
|
|
48
|
-
HybridObjectRegistry::registerHybridObjectConstructor(
|
|
49
|
-
"CactusUtil",
|
|
50
|
-
[]() -> std::shared_ptr<HybridObject> {
|
|
51
|
-
static_assert(std::is_default_constructible_v<HybridCactusUtil>,
|
|
52
|
-
"The HybridObject \"HybridCactusUtil\" is not default-constructible! "
|
|
53
|
-
"Create a public constructor that takes zero arguments to be able to autolink this HybridObject.");
|
|
54
|
-
return std::make_shared<HybridCactusUtil>();
|
|
55
|
-
}
|
|
56
|
-
);
|
|
57
45
|
HybridObjectRegistry::registerHybridObjectConstructor(
|
|
58
46
|
"CactusFileSystem",
|
|
59
47
|
[]() -> std::shared_ptr<HybridObject> {
|
|
@@ -61,20 +49,6 @@
|
|
|
61
49
|
return hybridObject;
|
|
62
50
|
}
|
|
63
51
|
);
|
|
64
|
-
HybridObjectRegistry::registerHybridObjectConstructor(
|
|
65
|
-
"CactusCrypto",
|
|
66
|
-
[]() -> std::shared_ptr<HybridObject> {
|
|
67
|
-
std::shared_ptr<HybridCactusCryptoSpec> hybridObject = Cactus::CactusAutolinking::createCactusCrypto();
|
|
68
|
-
return hybridObject;
|
|
69
|
-
}
|
|
70
|
-
);
|
|
71
|
-
HybridObjectRegistry::registerHybridObjectConstructor(
|
|
72
|
-
"CactusDeviceInfo",
|
|
73
|
-
[]() -> std::shared_ptr<HybridObject> {
|
|
74
|
-
std::shared_ptr<HybridCactusDeviceInfoSpec> hybridObject = Cactus::CactusAutolinking::createCactusDeviceInfo();
|
|
75
|
-
return hybridObject;
|
|
76
|
-
}
|
|
77
|
-
);
|
|
78
52
|
HybridObjectRegistry::registerHybridObjectConstructor(
|
|
79
53
|
"CactusImage",
|
|
80
54
|
[]() -> std::shared_ptr<HybridObject> {
|
|
@@ -23,36 +23,6 @@ public final class CactusAutolinking {
|
|
|
23
23
|
}()
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
/**
|
|
27
|
-
* Creates an instance of a Swift class that implements `HybridCactusCryptoSpec`,
|
|
28
|
-
* and wraps it in a Swift class that can directly interop with C++ (`HybridCactusCryptoSpec_cxx`)
|
|
29
|
-
*
|
|
30
|
-
* This is generated by Nitrogen and will initialize the class specified
|
|
31
|
-
* in the `"autolinking"` property of `nitro.json` (in this case, `HybridCactusCrypto`).
|
|
32
|
-
*/
|
|
33
|
-
public static func createCactusCrypto() -> bridge.std__shared_ptr_HybridCactusCryptoSpec_ {
|
|
34
|
-
let hybridObject = HybridCactusCrypto()
|
|
35
|
-
return { () -> bridge.std__shared_ptr_HybridCactusCryptoSpec_ in
|
|
36
|
-
let __cxxWrapped = hybridObject.getCxxWrapper()
|
|
37
|
-
return __cxxWrapped.getCxxPart()
|
|
38
|
-
}()
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Creates an instance of a Swift class that implements `HybridCactusDeviceInfoSpec`,
|
|
43
|
-
* and wraps it in a Swift class that can directly interop with C++ (`HybridCactusDeviceInfoSpec_cxx`)
|
|
44
|
-
*
|
|
45
|
-
* This is generated by Nitrogen and will initialize the class specified
|
|
46
|
-
* in the `"autolinking"` property of `nitro.json` (in this case, `HybridCactusDeviceInfo`).
|
|
47
|
-
*/
|
|
48
|
-
public static func createCactusDeviceInfo() -> bridge.std__shared_ptr_HybridCactusDeviceInfoSpec_ {
|
|
49
|
-
let hybridObject = HybridCactusDeviceInfo()
|
|
50
|
-
return { () -> bridge.std__shared_ptr_HybridCactusDeviceInfoSpec_ in
|
|
51
|
-
let __cxxWrapped = hybridObject.getCxxWrapper()
|
|
52
|
-
return __cxxWrapped.getCxxPart()
|
|
53
|
-
}()
|
|
54
|
-
}
|
|
55
|
-
|
|
56
26
|
/**
|
|
57
27
|
* Creates an instance of a Swift class that implements `HybridCactusImageSpec`,
|
|
58
28
|
* and wraps it in a Swift class that can directly interop with C++ (`HybridCactusImageSpec_cxx`)
|
|
@@ -19,12 +19,17 @@ namespace margelo::nitro::cactus {
|
|
|
19
19
|
prototype.registerHybridMethod("tokenize", &HybridCactusSpec::tokenize);
|
|
20
20
|
prototype.registerHybridMethod("scoreWindow", &HybridCactusSpec::scoreWindow);
|
|
21
21
|
prototype.registerHybridMethod("transcribe", &HybridCactusSpec::transcribe);
|
|
22
|
+
prototype.registerHybridMethod("streamTranscribeStart", &HybridCactusSpec::streamTranscribeStart);
|
|
23
|
+
prototype.registerHybridMethod("streamTranscribeProcess", &HybridCactusSpec::streamTranscribeProcess);
|
|
24
|
+
prototype.registerHybridMethod("streamTranscribeStop", &HybridCactusSpec::streamTranscribeStop);
|
|
25
|
+
prototype.registerHybridMethod("vad", &HybridCactusSpec::vad);
|
|
22
26
|
prototype.registerHybridMethod("embed", &HybridCactusSpec::embed);
|
|
23
27
|
prototype.registerHybridMethod("imageEmbed", &HybridCactusSpec::imageEmbed);
|
|
24
28
|
prototype.registerHybridMethod("audioEmbed", &HybridCactusSpec::audioEmbed);
|
|
25
29
|
prototype.registerHybridMethod("reset", &HybridCactusSpec::reset);
|
|
26
30
|
prototype.registerHybridMethod("stop", &HybridCactusSpec::stop);
|
|
27
31
|
prototype.registerHybridMethod("destroy", &HybridCactusSpec::destroy);
|
|
32
|
+
prototype.registerHybridMethod("setTelemetryEnvironment", &HybridCactusSpec::setTelemetryEnvironment);
|
|
28
33
|
});
|
|
29
34
|
}
|
|
30
35
|
|
|
@@ -53,17 +53,22 @@ namespace margelo::nitro::cactus {
|
|
|
53
53
|
|
|
54
54
|
public:
|
|
55
55
|
// Methods
|
|
56
|
-
virtual std::shared_ptr<Promise<void>> init(const std::string& modelPath,
|
|
56
|
+
virtual std::shared_ptr<Promise<void>> init(const std::string& modelPath, const std::optional<std::string>& corpusDir, std::optional<bool> cacheIndex) = 0;
|
|
57
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;
|
|
58
58
|
virtual std::shared_ptr<Promise<std::vector<double>>> tokenize(const std::string& text) = 0;
|
|
59
59
|
virtual std::shared_ptr<Promise<std::string>> scoreWindow(const std::vector<double>& tokens, double start, double end, double context) = 0;
|
|
60
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>> streamTranscribeStart(const std::optional<std::string>& optionsJson) = 0;
|
|
62
|
+
virtual std::shared_ptr<Promise<std::string>> streamTranscribeProcess(const std::vector<double>& audio) = 0;
|
|
63
|
+
virtual std::shared_ptr<Promise<std::string>> streamTranscribeStop() = 0;
|
|
64
|
+
virtual std::shared_ptr<Promise<std::string>> vad(const std::variant<std::vector<double>, std::string>& audio, double responseBufferSize, const std::optional<std::string>& optionsJson) = 0;
|
|
61
65
|
virtual std::shared_ptr<Promise<std::vector<double>>> embed(const std::string& text, double embeddingBufferSize, bool normalize) = 0;
|
|
62
66
|
virtual std::shared_ptr<Promise<std::vector<double>>> imageEmbed(const std::string& imagePath, double embeddingBufferSize) = 0;
|
|
63
67
|
virtual std::shared_ptr<Promise<std::vector<double>>> audioEmbed(const std::string& audioPath, double embeddingBufferSize) = 0;
|
|
64
68
|
virtual std::shared_ptr<Promise<void>> reset() = 0;
|
|
65
69
|
virtual std::shared_ptr<Promise<void>> stop() = 0;
|
|
66
70
|
virtual std::shared_ptr<Promise<void>> destroy() = 0;
|
|
71
|
+
virtual std::shared_ptr<Promise<void>> setTelemetryEnvironment(const std::string& cacheDir) = 0;
|
|
67
72
|
|
|
68
73
|
protected:
|
|
69
74
|
// Hybrid Setup
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cactus-react-native",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.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.
|
|
86
|
+
"react-native-nitro-modules": "^0.33.9",
|
|
87
87
|
"release-it": "^19.0.4",
|
|
88
88
|
"turbo": "^2.5.6",
|
|
89
89
|
"typescript": "^5.9.2"
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"peerDependencies": {
|
|
92
92
|
"react": "*",
|
|
93
93
|
"react-native": "*",
|
|
94
|
-
"react-native-nitro-modules": "^0.
|
|
94
|
+
"react-native-nitro-modules": "^0.33.9"
|
|
95
95
|
},
|
|
96
96
|
"workspaces": [
|
|
97
97
|
"example"
|
package/src/classes/CactusLM.ts
CHANGED
|
@@ -13,38 +13,51 @@ import type {
|
|
|
13
13
|
CactusLMImageEmbedResult,
|
|
14
14
|
CactusLMParams,
|
|
15
15
|
} from '../types/CactusLM';
|
|
16
|
-
import
|
|
17
|
-
import {
|
|
18
|
-
import { CactusConfig } from '../config/CactusConfig';
|
|
19
|
-
import { Database } from '../api/Database';
|
|
20
|
-
import { getErrorMessage } from '../utils/error';
|
|
21
|
-
import { RemoteLM } from '../api/RemoteLM';
|
|
16
|
+
import { getRegistry } from '../modelRegistry';
|
|
17
|
+
import type { CactusModel } from '../types/common';
|
|
22
18
|
|
|
23
19
|
export class CactusLM {
|
|
24
20
|
private readonly cactus = new Cactus();
|
|
25
21
|
|
|
26
22
|
private readonly model: string;
|
|
27
|
-
private readonly contextSize: number;
|
|
28
23
|
private readonly corpusDir?: string;
|
|
24
|
+
private readonly cacheIndex: boolean;
|
|
25
|
+
private readonly options: {
|
|
26
|
+
quantization: 'int4' | 'int8';
|
|
27
|
+
pro: boolean;
|
|
28
|
+
};
|
|
29
29
|
|
|
30
30
|
private isDownloading = false;
|
|
31
31
|
private isInitialized = false;
|
|
32
32
|
private isGenerating = false;
|
|
33
33
|
|
|
34
|
-
private static readonly defaultModel = 'qwen3-0.
|
|
35
|
-
private static readonly
|
|
34
|
+
private static readonly defaultModel = 'qwen3-0.6b';
|
|
35
|
+
private static readonly defaultOptions = {
|
|
36
|
+
quantization: 'int8' as const,
|
|
37
|
+
pro: false,
|
|
38
|
+
};
|
|
39
|
+
private static readonly quantizationExceptions: {
|
|
40
|
+
[model: string]: 'int4' | 'int8';
|
|
41
|
+
} = {
|
|
42
|
+
'gemma-3-270m-it': 'int8' as const,
|
|
43
|
+
'functiongemma-270m-it': 'int8' as const,
|
|
44
|
+
};
|
|
36
45
|
private static readonly defaultCompleteOptions = {
|
|
37
46
|
maxTokens: 512,
|
|
38
47
|
};
|
|
39
|
-
private static readonly defaultCompleteMode = 'local';
|
|
40
48
|
private static readonly defaultEmbedBufferSize = 2048;
|
|
41
49
|
|
|
42
|
-
constructor({ model,
|
|
43
|
-
Telemetry.init(CactusConfig.telemetryToken);
|
|
44
|
-
|
|
50
|
+
constructor({ model, corpusDir, cacheIndex, options }: CactusLMParams = {}) {
|
|
45
51
|
this.model = model ?? CactusLM.defaultModel;
|
|
46
|
-
this.contextSize = contextSize ?? CactusLM.defaultContextSize;
|
|
47
52
|
this.corpusDir = corpusDir;
|
|
53
|
+
this.cacheIndex = cacheIndex ?? false;
|
|
54
|
+
this.options = {
|
|
55
|
+
quantization:
|
|
56
|
+
options?.quantization ??
|
|
57
|
+
CactusLM.quantizationExceptions[this.model] ??
|
|
58
|
+
CactusLM.defaultOptions.quantization,
|
|
59
|
+
pro: options?.pro ?? CactusLM.defaultOptions.pro,
|
|
60
|
+
};
|
|
48
61
|
}
|
|
49
62
|
|
|
50
63
|
public async download({
|
|
@@ -59,17 +72,26 @@ export class CactusLM {
|
|
|
59
72
|
throw new Error('CactusLM is already downloading');
|
|
60
73
|
}
|
|
61
74
|
|
|
62
|
-
if (await CactusFileSystem.modelExists(this.
|
|
75
|
+
if (await CactusFileSystem.modelExists(this.getModelName())) {
|
|
76
|
+
console.log('Model already exists', this.getModelName());
|
|
63
77
|
onProgress?.(1.0);
|
|
64
78
|
return;
|
|
65
79
|
}
|
|
66
80
|
|
|
67
81
|
this.isDownloading = true;
|
|
68
82
|
try {
|
|
69
|
-
const
|
|
83
|
+
const registry = await getRegistry();
|
|
84
|
+
const modelConfig =
|
|
85
|
+
registry[this.model]?.quantization[this.options.quantization];
|
|
86
|
+
const url = this.options.pro ? modelConfig?.pro?.apple : modelConfig?.url;
|
|
87
|
+
|
|
88
|
+
if (!url) {
|
|
89
|
+
throw new Error(`Model ${this.model} with specified options not found`);
|
|
90
|
+
}
|
|
91
|
+
|
|
70
92
|
await CactusFileSystem.downloadModel(
|
|
71
|
-
this.
|
|
72
|
-
|
|
93
|
+
this.getModelName(),
|
|
94
|
+
url,
|
|
73
95
|
onProgress
|
|
74
96
|
);
|
|
75
97
|
} finally {
|
|
@@ -86,20 +108,19 @@ export class CactusLM {
|
|
|
86
108
|
if (this.isModelPath(this.model)) {
|
|
87
109
|
modelPath = this.model.replace('file://', '');
|
|
88
110
|
} else {
|
|
89
|
-
if (!(await CactusFileSystem.modelExists(this.
|
|
90
|
-
|
|
111
|
+
if (!(await CactusFileSystem.modelExists(this.getModelName()))) {
|
|
112
|
+
console.log('Model not found:', this.getModelName());
|
|
113
|
+
throw new Error(
|
|
114
|
+
`Model "${this.model}" with options ${JSON.stringify(this.options)} is not downloaded`
|
|
115
|
+
);
|
|
91
116
|
}
|
|
92
|
-
modelPath = await CactusFileSystem.getModelPath(this.
|
|
117
|
+
modelPath = await CactusFileSystem.getModelPath(this.getModelName());
|
|
93
118
|
}
|
|
94
119
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
} catch (error) {
|
|
100
|
-
Telemetry.logInit(this.model, false, getErrorMessage(error));
|
|
101
|
-
throw error;
|
|
102
|
-
}
|
|
120
|
+
const cacheDir = await CactusFileSystem.getCactusDirectory();
|
|
121
|
+
await this.cactus.setTelemetryEnvironment(cacheDir);
|
|
122
|
+
await this.cactus.init(modelPath, this.corpusDir, this.cacheIndex);
|
|
123
|
+
this.isInitialized = true;
|
|
103
124
|
}
|
|
104
125
|
|
|
105
126
|
public async complete({
|
|
@@ -107,7 +128,6 @@ export class CactusLM {
|
|
|
107
128
|
options,
|
|
108
129
|
tools,
|
|
109
130
|
onToken,
|
|
110
|
-
mode,
|
|
111
131
|
}: CactusLMCompleteParams): Promise<CactusLMCompleteResult> {
|
|
112
132
|
if (this.isGenerating) {
|
|
113
133
|
throw new Error('CactusLM is already generating');
|
|
@@ -118,49 +138,22 @@ export class CactusLM {
|
|
|
118
138
|
type: 'function' as const,
|
|
119
139
|
function: tool,
|
|
120
140
|
}));
|
|
121
|
-
mode = mode ?? CactusLM.defaultCompleteMode;
|
|
122
141
|
|
|
123
142
|
const responseBufferSize =
|
|
124
143
|
8 * (options.maxTokens ?? CactusLM.defaultCompleteOptions.maxTokens) +
|
|
125
144
|
256;
|
|
126
145
|
|
|
127
|
-
|
|
128
|
-
await this.init();
|
|
146
|
+
await this.init();
|
|
129
147
|
|
|
130
|
-
|
|
131
|
-
|
|
148
|
+
this.isGenerating = true;
|
|
149
|
+
try {
|
|
150
|
+
return await this.cactus.complete(
|
|
132
151
|
messages,
|
|
133
152
|
responseBufferSize,
|
|
134
153
|
options,
|
|
135
154
|
toolsInternal,
|
|
136
155
|
onToken
|
|
137
156
|
);
|
|
138
|
-
Telemetry.logCompletion(
|
|
139
|
-
this.model,
|
|
140
|
-
result.success,
|
|
141
|
-
result.success ? undefined : result.response,
|
|
142
|
-
result
|
|
143
|
-
);
|
|
144
|
-
return result;
|
|
145
|
-
} catch (localError) {
|
|
146
|
-
if (mode === 'local') {
|
|
147
|
-
Telemetry.logCompletion(this.model, false, getErrorMessage(localError));
|
|
148
|
-
throw localError;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
Telemetry.logCompletion(
|
|
152
|
-
this.model,
|
|
153
|
-
false,
|
|
154
|
-
`Local completion error: ${getErrorMessage(localError)}. Falling back to remote completion.`
|
|
155
|
-
);
|
|
156
|
-
|
|
157
|
-
try {
|
|
158
|
-
return RemoteLM.complete(messages, options, toolsInternal, onToken);
|
|
159
|
-
} catch (remoteError) {
|
|
160
|
-
throw new Error(
|
|
161
|
-
`Remote completion error: ${getErrorMessage(remoteError)}`
|
|
162
|
-
);
|
|
163
|
-
}
|
|
164
157
|
} finally {
|
|
165
158
|
this.isGenerating = false;
|
|
166
159
|
}
|
|
@@ -200,11 +193,7 @@ export class CactusLM {
|
|
|
200
193
|
CactusLM.defaultEmbedBufferSize,
|
|
201
194
|
normalize
|
|
202
195
|
);
|
|
203
|
-
Telemetry.logEmbedding(this.model, true);
|
|
204
196
|
return { embedding };
|
|
205
|
-
} catch (error) {
|
|
206
|
-
Telemetry.logEmbedding(this.model, false, getErrorMessage(error));
|
|
207
|
-
throw error;
|
|
208
197
|
} finally {
|
|
209
198
|
this.isGenerating = false;
|
|
210
199
|
}
|
|
@@ -225,11 +214,7 @@ export class CactusLM {
|
|
|
225
214
|
imagePath,
|
|
226
215
|
CactusLM.defaultEmbedBufferSize
|
|
227
216
|
);
|
|
228
|
-
Telemetry.logImageEmbedding(this.model, true);
|
|
229
217
|
return { embedding };
|
|
230
|
-
} catch (error) {
|
|
231
|
-
Telemetry.logImageEmbedding(this.model, false, getErrorMessage(error));
|
|
232
|
-
throw error;
|
|
233
218
|
} finally {
|
|
234
219
|
this.isGenerating = false;
|
|
235
220
|
}
|
|
@@ -256,14 +241,14 @@ export class CactusLM {
|
|
|
256
241
|
}
|
|
257
242
|
|
|
258
243
|
public async getModels(): Promise<CactusModel[]> {
|
|
259
|
-
|
|
260
|
-
for (const model of models) {
|
|
261
|
-
model.isDownloaded = await CactusFileSystem.modelExists(model.slug);
|
|
262
|
-
}
|
|
263
|
-
return models;
|
|
244
|
+
return Object.values(await getRegistry());
|
|
264
245
|
}
|
|
265
246
|
|
|
266
247
|
private isModelPath(model: string): boolean {
|
|
267
248
|
return model.startsWith('file://') || model.startsWith('/');
|
|
268
249
|
}
|
|
250
|
+
|
|
251
|
+
public getModelName(): string {
|
|
252
|
+
return `${this.model}-${this.options.quantization}${this.options.pro ? '-pro' : ''}`;
|
|
253
|
+
}
|
|
269
254
|
}
|