cactus-react-native 1.0.2 → 1.2.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.
Files changed (126) hide show
  1. package/README.md +378 -21
  2. package/android/src/main/java/com/margelo/nitro/cactus/HybridCactusCrypto.kt +23 -15
  3. package/android/src/main/java/com/margelo/nitro/cactus/HybridCactusDeviceInfo.kt +12 -9
  4. package/android/src/main/java/com/margelo/nitro/cactus/HybridCactusFileSystem.kt +42 -41
  5. package/android/src/main/java/com/margelo/nitro/cactus/HybridCactusImage.kt +81 -0
  6. package/android/src/main/jniLibs/arm64-v8a/libcactus.a +0 -0
  7. package/cpp/HybridCactus.cpp +105 -0
  8. package/cpp/HybridCactus.hpp +13 -0
  9. package/cpp/cactus_ffi.h +27 -0
  10. package/ios/HybridCactusImage.swift +53 -0
  11. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/cactus_ffi.h +27 -0
  12. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/engine.h +37 -5
  13. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ffi_utils.h +10 -9
  14. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/graph.h +49 -7
  15. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/kernel.h +31 -0
  16. package/ios/cactus.xcframework/ios-arm64/cactus.framework/cactus +0 -0
  17. package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/cactus_ffi.h +27 -0
  18. package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/engine.h +37 -5
  19. package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/ffi_utils.h +10 -9
  20. package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/graph.h +49 -7
  21. package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/kernel.h +31 -0
  22. package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/cactus +0 -0
  23. package/lib/module/api/Database.js +23 -0
  24. package/lib/module/api/Database.js.map +1 -1
  25. package/lib/module/api/RemoteLM.js +201 -0
  26. package/lib/module/api/RemoteLM.js.map +1 -0
  27. package/lib/module/classes/CactusLM.js +52 -26
  28. package/lib/module/classes/CactusLM.js.map +1 -1
  29. package/lib/module/classes/CactusSTT.js +139 -0
  30. package/lib/module/classes/CactusSTT.js.map +1 -0
  31. package/lib/module/config/CactusConfig.js +4 -0
  32. package/lib/module/config/CactusConfig.js.map +1 -1
  33. package/lib/module/constants/packageVersion.js +1 -1
  34. package/lib/module/hooks/useCactusLM.js +33 -10
  35. package/lib/module/hooks/useCactusLM.js.map +1 -1
  36. package/lib/module/hooks/useCactusSTT.js +234 -0
  37. package/lib/module/hooks/useCactusSTT.js.map +1 -0
  38. package/lib/module/index.js +2 -0
  39. package/lib/module/index.js.map +1 -1
  40. package/lib/module/native/Cactus.js +50 -1
  41. package/lib/module/native/Cactus.js.map +1 -1
  42. package/lib/module/native/CactusFileSystem.js +2 -3
  43. package/lib/module/native/CactusFileSystem.js.map +1 -1
  44. package/lib/module/native/CactusImage.js +13 -0
  45. package/lib/module/native/CactusImage.js.map +1 -0
  46. package/lib/module/native/index.js +1 -0
  47. package/lib/module/native/index.js.map +1 -1
  48. package/lib/module/specs/CactusImage.nitro.js +4 -0
  49. package/lib/module/specs/CactusImage.nitro.js.map +1 -0
  50. package/lib/module/telemetry/Telemetry.js +53 -1
  51. package/lib/module/telemetry/Telemetry.js.map +1 -1
  52. package/lib/module/types/CactusSTT.js +2 -0
  53. package/lib/module/types/CactusSTT.js.map +1 -0
  54. package/lib/typescript/src/api/Database.d.ts +1 -0
  55. package/lib/typescript/src/api/Database.d.ts.map +1 -1
  56. package/lib/typescript/src/api/RemoteLM.d.ts +14 -0
  57. package/lib/typescript/src/api/RemoteLM.d.ts.map +1 -0
  58. package/lib/typescript/src/classes/CactusLM.d.ts +6 -4
  59. package/lib/typescript/src/classes/CactusLM.d.ts.map +1 -1
  60. package/lib/typescript/src/classes/CactusSTT.d.ts +26 -0
  61. package/lib/typescript/src/classes/CactusSTT.d.ts.map +1 -0
  62. package/lib/typescript/src/config/CactusConfig.d.ts +1 -0
  63. package/lib/typescript/src/config/CactusConfig.d.ts.map +1 -1
  64. package/lib/typescript/src/constants/packageVersion.d.ts +1 -1
  65. package/lib/typescript/src/hooks/useCactusLM.d.ts +4 -3
  66. package/lib/typescript/src/hooks/useCactusLM.d.ts.map +1 -1
  67. package/lib/typescript/src/hooks/useCactusSTT.d.ts +20 -0
  68. package/lib/typescript/src/hooks/useCactusSTT.d.ts.map +1 -0
  69. package/lib/typescript/src/index.d.ts +4 -1
  70. package/lib/typescript/src/index.d.ts.map +1 -1
  71. package/lib/typescript/src/native/Cactus.d.ts +9 -2
  72. package/lib/typescript/src/native/Cactus.d.ts.map +1 -1
  73. package/lib/typescript/src/native/CactusFileSystem.d.ts +1 -1
  74. package/lib/typescript/src/native/CactusFileSystem.d.ts.map +1 -1
  75. package/lib/typescript/src/native/CactusImage.d.ts +6 -0
  76. package/lib/typescript/src/native/CactusImage.d.ts.map +1 -0
  77. package/lib/typescript/src/native/index.d.ts +1 -0
  78. package/lib/typescript/src/native/index.d.ts.map +1 -1
  79. package/lib/typescript/src/specs/Cactus.nitro.d.ts +3 -0
  80. package/lib/typescript/src/specs/Cactus.nitro.d.ts.map +1 -1
  81. package/lib/typescript/src/specs/CactusImage.nitro.d.ts +9 -0
  82. package/lib/typescript/src/specs/CactusImage.nitro.d.ts.map +1 -0
  83. package/lib/typescript/src/telemetry/Telemetry.d.ts +5 -1
  84. package/lib/typescript/src/telemetry/Telemetry.d.ts.map +1 -1
  85. package/lib/typescript/src/types/CactusLM.d.ts +8 -5
  86. package/lib/typescript/src/types/CactusLM.d.ts.map +1 -1
  87. package/lib/typescript/src/types/CactusSTT.d.ts +37 -0
  88. package/lib/typescript/src/types/CactusSTT.d.ts.map +1 -0
  89. package/nitro.json +4 -0
  90. package/nitrogen/generated/android/c++/JHybridCactusImageSpec.cpp +81 -0
  91. package/nitrogen/generated/android/c++/JHybridCactusImageSpec.hpp +66 -0
  92. package/nitrogen/generated/android/cactus+autolinking.cmake +2 -0
  93. package/nitrogen/generated/android/cactusOnLoad.cpp +10 -0
  94. package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/HybridCactusImageSpec.kt +62 -0
  95. package/nitrogen/generated/ios/Cactus-Swift-Cxx-Bridge.cpp +17 -0
  96. package/nitrogen/generated/ios/Cactus-Swift-Cxx-Bridge.hpp +17 -0
  97. package/nitrogen/generated/ios/Cactus-Swift-Cxx-Umbrella.hpp +5 -0
  98. package/nitrogen/generated/ios/CactusAutolinking.mm +8 -0
  99. package/nitrogen/generated/ios/CactusAutolinking.swift +15 -0
  100. package/nitrogen/generated/ios/c++/HybridCactusImageSpecSwift.cpp +11 -0
  101. package/nitrogen/generated/ios/c++/HybridCactusImageSpecSwift.hpp +85 -0
  102. package/nitrogen/generated/ios/swift/HybridCactusImageSpec.swift +58 -0
  103. package/nitrogen/generated/ios/swift/HybridCactusImageSpec_cxx.swift +158 -0
  104. package/nitrogen/generated/shared/c++/HybridCactusImageSpec.cpp +22 -0
  105. package/nitrogen/generated/shared/c++/HybridCactusImageSpec.hpp +64 -0
  106. package/nitrogen/generated/shared/c++/HybridCactusSpec.cpp +3 -0
  107. package/nitrogen/generated/shared/c++/HybridCactusSpec.hpp +3 -0
  108. package/package.json +1 -1
  109. package/src/api/Database.ts +27 -0
  110. package/src/api/RemoteLM.ts +273 -0
  111. package/src/classes/CactusLM.ts +72 -38
  112. package/src/classes/CactusSTT.ts +188 -0
  113. package/src/config/CactusConfig.ts +4 -0
  114. package/src/constants/packageVersion.ts +1 -1
  115. package/src/hooks/useCactusLM.ts +45 -17
  116. package/src/hooks/useCactusSTT.ts +285 -0
  117. package/src/index.tsx +14 -2
  118. package/src/native/Cactus.ts +94 -4
  119. package/src/native/CactusFileSystem.ts +2 -2
  120. package/src/native/CactusImage.ts +20 -0
  121. package/src/native/index.ts +1 -0
  122. package/src/specs/Cactus.nitro.ts +9 -0
  123. package/src/specs/CactusImage.nitro.ts +12 -0
  124. package/src/telemetry/Telemetry.ts +78 -1
  125. package/src/types/CactusLM.ts +9 -5
  126. package/src/types/CactusSTT.ts +42 -0
@@ -0,0 +1,62 @@
1
+ ///
2
+ /// HybridCactusImageSpec.kt
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ package com.margelo.nitro.cactus
9
+
10
+ import androidx.annotation.Keep
11
+ import com.facebook.jni.HybridData
12
+ import com.facebook.proguard.annotations.DoNotStrip
13
+ import com.margelo.nitro.core.Promise
14
+ import com.margelo.nitro.core.HybridObject
15
+
16
+ /**
17
+ * A Kotlin class representing the CactusImage HybridObject.
18
+ * Implement this abstract class to create Kotlin-based instances of CactusImage.
19
+ */
20
+ @DoNotStrip
21
+ @Keep
22
+ @Suppress(
23
+ "KotlinJniMissingFunction", "unused",
24
+ "RedundantSuppression", "RedundantUnitReturnType", "SimpleRedundantLet",
25
+ "LocalVariableName", "PropertyName", "PrivatePropertyName", "FunctionName"
26
+ )
27
+ abstract class HybridCactusImageSpec: HybridObject() {
28
+ @DoNotStrip
29
+ private var mHybridData: HybridData = initHybrid()
30
+
31
+ init {
32
+ super.updateNative(mHybridData)
33
+ }
34
+
35
+ override fun updateNative(hybridData: HybridData) {
36
+ mHybridData = hybridData
37
+ super.updateNative(hybridData)
38
+ }
39
+
40
+ // Default implementation of `HybridObject.toString()`
41
+ override fun toString(): String {
42
+ return "[HybridObject CactusImage]"
43
+ }
44
+
45
+ // Properties
46
+
47
+
48
+ // Methods
49
+ @DoNotStrip
50
+ @Keep
51
+ abstract fun base64(path: String): Promise<String>
52
+
53
+ @DoNotStrip
54
+ @Keep
55
+ abstract fun resize(path: String, height: Double, width: Double, quality: Double): Promise<String>
56
+
57
+ private external fun initHybrid(): HybridData
58
+
59
+ companion object {
60
+ protected const val TAG = "HybridCactusImageSpec"
61
+ }
62
+ }
@@ -12,6 +12,7 @@
12
12
  #include "HybridCactusCryptoSpecSwift.hpp"
13
13
  #include "HybridCactusDeviceInfoSpecSwift.hpp"
14
14
  #include "HybridCactusFileSystemSpecSwift.hpp"
15
+ #include "HybridCactusImageSpecSwift.hpp"
15
16
 
16
17
  namespace margelo::nitro::cactus::bridge::swift {
17
18
 
@@ -118,5 +119,21 @@ namespace margelo::nitro::cactus::bridge::swift {
118
119
  Cactus::HybridCactusFileSystemSpec_cxx& swiftPart = swiftWrapper->getSwiftPart();
119
120
  return swiftPart.toUnsafe();
120
121
  }
122
+
123
+ // pragma MARK: std::shared_ptr<HybridCactusImageSpec>
124
+ std::shared_ptr<HybridCactusImageSpec> create_std__shared_ptr_HybridCactusImageSpec_(void* NON_NULL swiftUnsafePointer) noexcept {
125
+ Cactus::HybridCactusImageSpec_cxx swiftPart = Cactus::HybridCactusImageSpec_cxx::fromUnsafe(swiftUnsafePointer);
126
+ return std::make_shared<margelo::nitro::cactus::HybridCactusImageSpecSwift>(swiftPart);
127
+ }
128
+ void* NON_NULL get_std__shared_ptr_HybridCactusImageSpec_(std__shared_ptr_HybridCactusImageSpec_ cppType) {
129
+ std::shared_ptr<margelo::nitro::cactus::HybridCactusImageSpecSwift> swiftWrapper = std::dynamic_pointer_cast<margelo::nitro::cactus::HybridCactusImageSpecSwift>(cppType);
130
+ #ifdef NITRO_DEBUG
131
+ if (swiftWrapper == nullptr) [[unlikely]] {
132
+ throw std::runtime_error("Class \"HybridCactusImageSpec\" is not implemented in Swift!");
133
+ }
134
+ #endif
135
+ Cactus::HybridCactusImageSpec_cxx& swiftPart = swiftWrapper->getSwiftPart();
136
+ return swiftPart.toUnsafe();
137
+ }
121
138
 
122
139
  } // namespace margelo::nitro::cactus::bridge::swift
@@ -16,6 +16,8 @@ namespace margelo::nitro::cactus { class HybridCactusCryptoSpec; }
16
16
  namespace margelo::nitro::cactus { class HybridCactusDeviceInfoSpec; }
17
17
  // Forward declaration of `HybridCactusFileSystemSpec` to properly resolve imports.
18
18
  namespace margelo::nitro::cactus { class HybridCactusFileSystemSpec; }
19
+ // Forward declaration of `HybridCactusImageSpec` to properly resolve imports.
20
+ namespace margelo::nitro::cactus { class HybridCactusImageSpec; }
19
21
 
20
22
  // Forward declarations of Swift defined types
21
23
  // Forward declaration of `HybridCactusCryptoSpec_cxx` to properly resolve imports.
@@ -24,12 +26,15 @@ namespace Cactus { class HybridCactusCryptoSpec_cxx; }
24
26
  namespace Cactus { class HybridCactusDeviceInfoSpec_cxx; }
25
27
  // Forward declaration of `HybridCactusFileSystemSpec_cxx` to properly resolve imports.
26
28
  namespace Cactus { class HybridCactusFileSystemSpec_cxx; }
29
+ // Forward declaration of `HybridCactusImageSpec_cxx` to properly resolve imports.
30
+ namespace Cactus { class HybridCactusImageSpec_cxx; }
27
31
 
28
32
  // Include C++ defined types
29
33
  #include "DeviceInfo.hpp"
30
34
  #include "HybridCactusCryptoSpec.hpp"
31
35
  #include "HybridCactusDeviceInfoSpec.hpp"
32
36
  #include "HybridCactusFileSystemSpec.hpp"
37
+ #include "HybridCactusImageSpec.hpp"
33
38
  #include <NitroModules/Promise.hpp>
34
39
  #include <NitroModules/PromiseHolder.hpp>
35
40
  #include <NitroModules/Result.hpp>
@@ -369,5 +374,17 @@ namespace margelo::nitro::cactus::bridge::swift {
369
374
  inline Result_std__shared_ptr_Promise_void___ create_Result_std__shared_ptr_Promise_void___(const std::exception_ptr& error) noexcept {
370
375
  return Result<std::shared_ptr<Promise<void>>>::withError(error);
371
376
  }
377
+
378
+ // pragma MARK: std::shared_ptr<HybridCactusImageSpec>
379
+ /**
380
+ * Specialized version of `std::shared_ptr<HybridCactusImageSpec>`.
381
+ */
382
+ using std__shared_ptr_HybridCactusImageSpec_ = std::shared_ptr<HybridCactusImageSpec>;
383
+ std::shared_ptr<HybridCactusImageSpec> create_std__shared_ptr_HybridCactusImageSpec_(void* NON_NULL swiftUnsafePointer) noexcept;
384
+ void* NON_NULL get_std__shared_ptr_HybridCactusImageSpec_(std__shared_ptr_HybridCactusImageSpec_ cppType);
385
+
386
+ // pragma MARK: std::weak_ptr<HybridCactusImageSpec>
387
+ using std__weak_ptr_HybridCactusImageSpec_ = std::weak_ptr<HybridCactusImageSpec>;
388
+ inline std__weak_ptr_HybridCactusImageSpec_ weakify_std__shared_ptr_HybridCactusImageSpec_(const std::shared_ptr<HybridCactusImageSpec>& strong) noexcept { return strong; }
372
389
 
373
390
  } // namespace margelo::nitro::cactus::bridge::swift
@@ -16,12 +16,15 @@ namespace margelo::nitro::cactus { class HybridCactusCryptoSpec; }
16
16
  namespace margelo::nitro::cactus { class HybridCactusDeviceInfoSpec; }
17
17
  // Forward declaration of `HybridCactusFileSystemSpec` to properly resolve imports.
18
18
  namespace margelo::nitro::cactus { class HybridCactusFileSystemSpec; }
19
+ // Forward declaration of `HybridCactusImageSpec` to properly resolve imports.
20
+ namespace margelo::nitro::cactus { class HybridCactusImageSpec; }
19
21
 
20
22
  // Include C++ defined types
21
23
  #include "DeviceInfo.hpp"
22
24
  #include "HybridCactusCryptoSpec.hpp"
23
25
  #include "HybridCactusDeviceInfoSpec.hpp"
24
26
  #include "HybridCactusFileSystemSpec.hpp"
27
+ #include "HybridCactusImageSpec.hpp"
25
28
  #include <NitroModules/Promise.hpp>
26
29
  #include <NitroModules/Result.hpp>
27
30
  #include <exception>
@@ -46,6 +49,8 @@ namespace Cactus { class HybridCactusCryptoSpec_cxx; }
46
49
  namespace Cactus { class HybridCactusDeviceInfoSpec_cxx; }
47
50
  // Forward declaration of `HybridCactusFileSystemSpec_cxx` to properly resolve imports.
48
51
  namespace Cactus { class HybridCactusFileSystemSpec_cxx; }
52
+ // Forward declaration of `HybridCactusImageSpec_cxx` to properly resolve imports.
53
+ namespace Cactus { class HybridCactusImageSpec_cxx; }
49
54
 
50
55
  // Include Swift defined types
51
56
  #if __has_include("Cactus-Swift.h")
@@ -15,6 +15,7 @@
15
15
  #include "HybridCactusFileSystemSpecSwift.hpp"
16
16
  #include "HybridCactusCryptoSpecSwift.hpp"
17
17
  #include "HybridCactusDeviceInfoSpecSwift.hpp"
18
+ #include "HybridCactusImageSpecSwift.hpp"
18
19
 
19
20
  @interface CactusAutolinking : NSObject
20
21
  @end
@@ -64,6 +65,13 @@
64
65
  return hybridObject;
65
66
  }
66
67
  );
68
+ HybridObjectRegistry::registerHybridObjectConstructor(
69
+ "CactusImage",
70
+ []() -> std::shared_ptr<HybridObject> {
71
+ std::shared_ptr<HybridCactusImageSpec> hybridObject = Cactus::CactusAutolinking::createCactusImage();
72
+ return hybridObject;
73
+ }
74
+ );
67
75
  }
68
76
 
69
77
  @end
@@ -52,4 +52,19 @@ public final class CactusAutolinking {
52
52
  return __cxxWrapped.getCxxPart()
53
53
  }()
54
54
  }
55
+
56
+ /**
57
+ * Creates an instance of a Swift class that implements `HybridCactusImageSpec`,
58
+ * and wraps it in a Swift class that can directly interop with C++ (`HybridCactusImageSpec_cxx`)
59
+ *
60
+ * This is generated by Nitrogen and will initialize the class specified
61
+ * in the `"autolinking"` property of `nitro.json` (in this case, `HybridCactusImage`).
62
+ */
63
+ public static func createCactusImage() -> bridge.std__shared_ptr_HybridCactusImageSpec_ {
64
+ let hybridObject = HybridCactusImage()
65
+ return { () -> bridge.std__shared_ptr_HybridCactusImageSpec_ in
66
+ let __cxxWrapped = hybridObject.getCxxWrapper()
67
+ return __cxxWrapped.getCxxPart()
68
+ }()
69
+ }
55
70
  }
@@ -0,0 +1,11 @@
1
+ ///
2
+ /// HybridCactusImageSpecSwift.cpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #include "HybridCactusImageSpecSwift.hpp"
9
+
10
+ namespace margelo::nitro::cactus {
11
+ } // namespace margelo::nitro::cactus
@@ -0,0 +1,85 @@
1
+ ///
2
+ /// HybridCactusImageSpecSwift.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #include "HybridCactusImageSpec.hpp"
11
+
12
+ // Forward declaration of `HybridCactusImageSpec_cxx` to properly resolve imports.
13
+ namespace Cactus { class HybridCactusImageSpec_cxx; }
14
+
15
+
16
+
17
+ #include <string>
18
+ #include <NitroModules/Promise.hpp>
19
+
20
+ #include "Cactus-Swift-Cxx-Umbrella.hpp"
21
+
22
+ namespace margelo::nitro::cactus {
23
+
24
+ /**
25
+ * The C++ part of HybridCactusImageSpec_cxx.swift.
26
+ *
27
+ * HybridCactusImageSpecSwift (C++) accesses HybridCactusImageSpec_cxx (Swift), and might
28
+ * contain some additional bridging code for C++ <> Swift interop.
29
+ *
30
+ * Since this obviously introduces an overhead, I hope at some point in
31
+ * the future, HybridCactusImageSpec_cxx can directly inherit from the C++ class HybridCactusImageSpec
32
+ * to simplify the whole structure and memory management.
33
+ */
34
+ class HybridCactusImageSpecSwift: public virtual HybridCactusImageSpec {
35
+ public:
36
+ // Constructor from a Swift instance
37
+ explicit HybridCactusImageSpecSwift(const Cactus::HybridCactusImageSpec_cxx& swiftPart):
38
+ HybridObject(HybridCactusImageSpec::TAG),
39
+ _swiftPart(swiftPart) { }
40
+
41
+ public:
42
+ // Get the Swift part
43
+ inline Cactus::HybridCactusImageSpec_cxx& getSwiftPart() noexcept {
44
+ return _swiftPart;
45
+ }
46
+
47
+ public:
48
+ inline size_t getExternalMemorySize() noexcept override {
49
+ return _swiftPart.getMemorySize();
50
+ }
51
+ void dispose() noexcept override {
52
+ _swiftPart.dispose();
53
+ }
54
+ std::string toString() override {
55
+ return _swiftPart.toString();
56
+ }
57
+
58
+ public:
59
+ // Properties
60
+
61
+
62
+ public:
63
+ // Methods
64
+ inline std::shared_ptr<Promise<std::string>> base64(const std::string& path) override {
65
+ auto __result = _swiftPart.base64(path);
66
+ if (__result.hasError()) [[unlikely]] {
67
+ std::rethrow_exception(__result.error());
68
+ }
69
+ auto __value = std::move(__result.value());
70
+ return __value;
71
+ }
72
+ inline std::shared_ptr<Promise<std::string>> resize(const std::string& path, double height, double width, double quality) override {
73
+ auto __result = _swiftPart.resize(path, std::forward<decltype(height)>(height), std::forward<decltype(width)>(width), std::forward<decltype(quality)>(quality));
74
+ if (__result.hasError()) [[unlikely]] {
75
+ std::rethrow_exception(__result.error());
76
+ }
77
+ auto __value = std::move(__result.value());
78
+ return __value;
79
+ }
80
+
81
+ private:
82
+ Cactus::HybridCactusImageSpec_cxx _swiftPart;
83
+ };
84
+
85
+ } // namespace margelo::nitro::cactus
@@ -0,0 +1,58 @@
1
+ ///
2
+ /// HybridCactusImageSpec.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ import Foundation
9
+ import NitroModules
10
+ import NitroModules
11
+
12
+ /// See ``HybridCactusImageSpec``
13
+ public protocol HybridCactusImageSpec_protocol: HybridObject {
14
+ // Properties
15
+
16
+
17
+ // Methods
18
+ func base64(path: String) throws -> Promise<String>
19
+ func resize(path: String, height: Double, width: Double, quality: Double) throws -> Promise<String>
20
+ }
21
+
22
+ public extension HybridCactusImageSpec_protocol {
23
+ /// Default implementation of ``HybridObject.toString``
24
+ func toString() -> String {
25
+ return "[HybridObject CactusImage]"
26
+ }
27
+ }
28
+
29
+ /// See ``HybridCactusImageSpec``
30
+ open class HybridCactusImageSpec_base {
31
+ private weak var cxxWrapper: HybridCactusImageSpec_cxx? = nil
32
+ public init() { }
33
+ public func getCxxWrapper() -> HybridCactusImageSpec_cxx {
34
+ #if DEBUG
35
+ guard self is HybridCactusImageSpec else {
36
+ fatalError("`self` is not a `HybridCactusImageSpec`! Did you accidentally inherit from `HybridCactusImageSpec_base` instead of `HybridCactusImageSpec`?")
37
+ }
38
+ #endif
39
+ if let cxxWrapper = self.cxxWrapper {
40
+ return cxxWrapper
41
+ } else {
42
+ let cxxWrapper = HybridCactusImageSpec_cxx(self as! HybridCactusImageSpec)
43
+ self.cxxWrapper = cxxWrapper
44
+ return cxxWrapper
45
+ }
46
+ }
47
+ }
48
+
49
+ /**
50
+ * A Swift base-protocol representing the CactusImage HybridObject.
51
+ * Implement this protocol to create Swift-based instances of CactusImage.
52
+ * ```swift
53
+ * class HybridCactusImage : HybridCactusImageSpec {
54
+ * // ...
55
+ * }
56
+ * ```
57
+ */
58
+ public typealias HybridCactusImageSpec = HybridCactusImageSpec_protocol & HybridCactusImageSpec_base
@@ -0,0 +1,158 @@
1
+ ///
2
+ /// HybridCactusImageSpec_cxx.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ import Foundation
9
+ import NitroModules
10
+ import NitroModules
11
+
12
+ /**
13
+ * A class implementation that bridges HybridCactusImageSpec over to C++.
14
+ * In C++, we cannot use Swift protocols - so we need to wrap it in a class to make it strongly defined.
15
+ *
16
+ * Also, some Swift types need to be bridged with special handling:
17
+ * - Enums need to be wrapped in Structs, otherwise they cannot be accessed bi-directionally (Swift bug: https://github.com/swiftlang/swift/issues/75330)
18
+ * - Other HybridObjects need to be wrapped/unwrapped from the Swift TCxx wrapper
19
+ * - Throwing methods need to be wrapped with a Result<T, Error> type, as exceptions cannot be propagated to C++
20
+ */
21
+ open class HybridCactusImageSpec_cxx {
22
+ /**
23
+ * The Swift <> C++ bridge's namespace (`margelo::nitro::cactus::bridge::swift`)
24
+ * from `Cactus-Swift-Cxx-Bridge.hpp`.
25
+ * This contains specialized C++ templates, and C++ helper functions that can be accessed from Swift.
26
+ */
27
+ public typealias bridge = margelo.nitro.cactus.bridge.swift
28
+
29
+ /**
30
+ * Holds an instance of the `HybridCactusImageSpec` Swift protocol.
31
+ */
32
+ private var __implementation: any HybridCactusImageSpec
33
+
34
+ /**
35
+ * Holds a weak pointer to the C++ class that wraps the Swift class.
36
+ */
37
+ private var __cxxPart: bridge.std__weak_ptr_HybridCactusImageSpec_
38
+
39
+ /**
40
+ * Create a new `HybridCactusImageSpec_cxx` that wraps the given `HybridCactusImageSpec`.
41
+ * All properties and methods bridge to C++ types.
42
+ */
43
+ public init(_ implementation: any HybridCactusImageSpec) {
44
+ self.__implementation = implementation
45
+ self.__cxxPart = .init()
46
+ /* no base class */
47
+ }
48
+
49
+ /**
50
+ * Get the actual `HybridCactusImageSpec` instance this class wraps.
51
+ */
52
+ @inline(__always)
53
+ public func getHybridCactusImageSpec() -> any HybridCactusImageSpec {
54
+ return __implementation
55
+ }
56
+
57
+ /**
58
+ * Casts this instance to a retained unsafe raw pointer.
59
+ * This acquires one additional strong reference on the object!
60
+ */
61
+ public func toUnsafe() -> UnsafeMutableRawPointer {
62
+ return Unmanaged.passRetained(self).toOpaque()
63
+ }
64
+
65
+ /**
66
+ * Casts an unsafe pointer to a `HybridCactusImageSpec_cxx`.
67
+ * The pointer has to be a retained opaque `Unmanaged<HybridCactusImageSpec_cxx>`.
68
+ * This removes one strong reference from the object!
69
+ */
70
+ public class func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> HybridCactusImageSpec_cxx {
71
+ return Unmanaged<HybridCactusImageSpec_cxx>.fromOpaque(pointer).takeRetainedValue()
72
+ }
73
+
74
+ /**
75
+ * Gets (or creates) the C++ part of this Hybrid Object.
76
+ * The C++ part is a `std::shared_ptr<HybridCactusImageSpec>`.
77
+ */
78
+ public func getCxxPart() -> bridge.std__shared_ptr_HybridCactusImageSpec_ {
79
+ let cachedCxxPart = self.__cxxPart.lock()
80
+ if Bool(fromCxx: cachedCxxPart) {
81
+ return cachedCxxPart
82
+ } else {
83
+ let newCxxPart = bridge.create_std__shared_ptr_HybridCactusImageSpec_(self.toUnsafe())
84
+ __cxxPart = bridge.weakify_std__shared_ptr_HybridCactusImageSpec_(newCxxPart)
85
+ return newCxxPart
86
+ }
87
+ }
88
+
89
+
90
+
91
+ /**
92
+ * Get the memory size of the Swift class (plus size of any other allocations)
93
+ * so the JS VM can properly track it and garbage-collect the JS object if needed.
94
+ */
95
+ @inline(__always)
96
+ public var memorySize: Int {
97
+ return MemoryHelper.getSizeOf(self.__implementation) + self.__implementation.memorySize
98
+ }
99
+
100
+ /**
101
+ * Call dispose() on the Swift class.
102
+ * This _may_ be called manually from JS.
103
+ */
104
+ @inline(__always)
105
+ public func dispose() {
106
+ self.__implementation.dispose()
107
+ }
108
+
109
+ /**
110
+ * Call toString() on the Swift class.
111
+ */
112
+ @inline(__always)
113
+ public func toString() -> String {
114
+ return self.__implementation.toString()
115
+ }
116
+
117
+ // Properties
118
+
119
+
120
+ // Methods
121
+ @inline(__always)
122
+ public final func base64(path: std.string) -> bridge.Result_std__shared_ptr_Promise_std__string___ {
123
+ do {
124
+ let __result = try self.__implementation.base64(path: String(path))
125
+ let __resultCpp = { () -> bridge.std__shared_ptr_Promise_std__string__ in
126
+ let __promise = bridge.create_std__shared_ptr_Promise_std__string__()
127
+ let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__string__(__promise)
128
+ __result
129
+ .then({ __result in __promiseHolder.resolve(std.string(__result)) })
130
+ .catch({ __error in __promiseHolder.reject(__error.toCpp()) })
131
+ return __promise
132
+ }()
133
+ return bridge.create_Result_std__shared_ptr_Promise_std__string___(__resultCpp)
134
+ } catch (let __error) {
135
+ let __exceptionPtr = __error.toCpp()
136
+ return bridge.create_Result_std__shared_ptr_Promise_std__string___(__exceptionPtr)
137
+ }
138
+ }
139
+
140
+ @inline(__always)
141
+ public final func resize(path: std.string, height: Double, width: Double, quality: Double) -> bridge.Result_std__shared_ptr_Promise_std__string___ {
142
+ do {
143
+ let __result = try self.__implementation.resize(path: String(path), height: height, width: width, quality: quality)
144
+ let __resultCpp = { () -> bridge.std__shared_ptr_Promise_std__string__ in
145
+ let __promise = bridge.create_std__shared_ptr_Promise_std__string__()
146
+ let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__string__(__promise)
147
+ __result
148
+ .then({ __result in __promiseHolder.resolve(std.string(__result)) })
149
+ .catch({ __error in __promiseHolder.reject(__error.toCpp()) })
150
+ return __promise
151
+ }()
152
+ return bridge.create_Result_std__shared_ptr_Promise_std__string___(__resultCpp)
153
+ } catch (let __error) {
154
+ let __exceptionPtr = __error.toCpp()
155
+ return bridge.create_Result_std__shared_ptr_Promise_std__string___(__exceptionPtr)
156
+ }
157
+ }
158
+ }
@@ -0,0 +1,22 @@
1
+ ///
2
+ /// HybridCactusImageSpec.cpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #include "HybridCactusImageSpec.hpp"
9
+
10
+ namespace margelo::nitro::cactus {
11
+
12
+ void HybridCactusImageSpec::loadHybridMethods() {
13
+ // load base methods/properties
14
+ HybridObject::loadHybridMethods();
15
+ // load custom methods/properties
16
+ registerHybrids(this, [](Prototype& prototype) {
17
+ prototype.registerHybridMethod("base64", &HybridCactusImageSpec::base64);
18
+ prototype.registerHybridMethod("resize", &HybridCactusImageSpec::resize);
19
+ });
20
+ }
21
+
22
+ } // namespace margelo::nitro::cactus
@@ -0,0 +1,64 @@
1
+ ///
2
+ /// HybridCactusImageSpec.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 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
+
17
+
18
+ #include <string>
19
+ #include <NitroModules/Promise.hpp>
20
+
21
+ namespace margelo::nitro::cactus {
22
+
23
+ using namespace margelo::nitro;
24
+
25
+ /**
26
+ * An abstract base class for `CactusImage`
27
+ * Inherit this class to create instances of `HybridCactusImageSpec` in C++.
28
+ * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
29
+ * @example
30
+ * ```cpp
31
+ * class HybridCactusImage: public HybridCactusImageSpec {
32
+ * public:
33
+ * HybridCactusImage(...): HybridObject(TAG) { ... }
34
+ * // ...
35
+ * };
36
+ * ```
37
+ */
38
+ class HybridCactusImageSpec: public virtual HybridObject {
39
+ public:
40
+ // Constructor
41
+ explicit HybridCactusImageSpec(): HybridObject(TAG) { }
42
+
43
+ // Destructor
44
+ ~HybridCactusImageSpec() override = default;
45
+
46
+ public:
47
+ // Properties
48
+
49
+
50
+ public:
51
+ // Methods
52
+ virtual std::shared_ptr<Promise<std::string>> base64(const std::string& path) = 0;
53
+ virtual std::shared_ptr<Promise<std::string>> resize(const std::string& path, double height, double width, double quality) = 0;
54
+
55
+ protected:
56
+ // Hybrid Setup
57
+ void loadHybridMethods() override;
58
+
59
+ protected:
60
+ // Tag for logging
61
+ static constexpr auto TAG = "CactusImage";
62
+ };
63
+
64
+ } // namespace margelo::nitro::cactus
@@ -16,7 +16,10 @@ 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("transcribe", &HybridCactusSpec::transcribe);
19
20
  prototype.registerHybridMethod("embed", &HybridCactusSpec::embed);
21
+ prototype.registerHybridMethod("imageEmbed", &HybridCactusSpec::imageEmbed);
22
+ prototype.registerHybridMethod("audioEmbed", &HybridCactusSpec::audioEmbed);
20
23
  prototype.registerHybridMethod("reset", &HybridCactusSpec::reset);
21
24
  prototype.registerHybridMethod("stop", &HybridCactusSpec::stop);
22
25
  prototype.registerHybridMethod("destroy", &HybridCactusSpec::destroy);
@@ -54,7 +54,10 @@ namespace margelo::nitro::cactus {
54
54
  // Methods
55
55
  virtual std::shared_ptr<Promise<void>> init(const std::string& modelPath, double contextSize, const std::optional<std::string>& corpusDir) = 0;
56
56
  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::string>> transcribe(const std::string& audioFilePath, 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;
57
58
  virtual std::shared_ptr<Promise<std::vector<double>>> embed(const std::string& text, double embeddingBufferSize) = 0;
59
+ virtual std::shared_ptr<Promise<std::vector<double>>> imageEmbed(const std::string& imagePath, double embeddingBufferSize) = 0;
60
+ virtual std::shared_ptr<Promise<std::vector<double>>> audioEmbed(const std::string& audioPath, double embeddingBufferSize) = 0;
58
61
  virtual std::shared_ptr<Promise<void>> reset() = 0;
59
62
  virtual std::shared_ptr<Promise<void>> stop() = 0;
60
63
  virtual std::shared_ptr<Promise<void>> destroy() = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cactus-react-native",
3
- "version": "1.0.2",
3
+ "version": "1.2.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",
@@ -54,6 +54,33 @@ export class Database {
54
54
  return await CactusUtil.registerApp(await response.text());
55
55
  }
56
56
 
57
+ public static async getModel(slug: string): Promise<CactusModel> {
58
+ const response = await fetch(
59
+ `${this.url}/functions/v1/get-models?slug=${slug}&sdk_name=react&sdk_version=${packageVersion}`,
60
+ {
61
+ headers: { apikey: this.key, Authorization: `Bearer ${this.key}` },
62
+ }
63
+ );
64
+
65
+ if (!response.ok) {
66
+ throw new Error('Getting model failed');
67
+ }
68
+
69
+ const model = (await response.json()) as CactusModelResponse;
70
+
71
+ return {
72
+ name: model.name,
73
+ slug: model.slug,
74
+ quantization: model.quantization,
75
+ sizeMb: model.size_mb,
76
+ downloadUrl: model.download_url,
77
+ supportsToolCalling: model.supports_tool_calling,
78
+ supportsVision: model.supports_vision,
79
+ createdAt: model.created_at,
80
+ isDownloaded: false,
81
+ };
82
+ }
83
+
57
84
  public static async getModels(): Promise<CactusModel[]> {
58
85
  const response = await fetch(
59
86
  `${this.url}/functions/v1/get-models?sdk_name=react&sdk_version=${packageVersion}`,