react-native-nitro-mlx 0.1.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 (63) hide show
  1. package/MLXReactNative.podspec +42 -0
  2. package/ios/Bridge.h +8 -0
  3. package/ios/Sources/MLXReactNative.h +16 -0
  4. package/lib/module/index.js +6 -0
  5. package/lib/module/index.js.map +1 -0
  6. package/lib/module/llm.js +105 -0
  7. package/lib/module/llm.js.map +1 -0
  8. package/lib/module/modelManager.js +79 -0
  9. package/lib/module/modelManager.js.map +1 -0
  10. package/lib/module/models.js +41 -0
  11. package/lib/module/models.js.map +1 -0
  12. package/lib/module/package.json +1 -0
  13. package/lib/module/specs/LLM.nitro.js +4 -0
  14. package/lib/module/specs/LLM.nitro.js.map +1 -0
  15. package/lib/module/specs/ModelManager.nitro.js +4 -0
  16. package/lib/module/specs/ModelManager.nitro.js.map +1 -0
  17. package/lib/typescript/package.json +1 -0
  18. package/lib/typescript/src/index.d.ts +6 -0
  19. package/lib/typescript/src/index.d.ts.map +1 -0
  20. package/lib/typescript/src/llm.d.ts +69 -0
  21. package/lib/typescript/src/llm.d.ts.map +1 -0
  22. package/lib/typescript/src/modelManager.d.ts +53 -0
  23. package/lib/typescript/src/modelManager.d.ts.map +1 -0
  24. package/lib/typescript/src/models.d.ts +29 -0
  25. package/lib/typescript/src/models.d.ts.map +1 -0
  26. package/lib/typescript/src/specs/LLM.nitro.d.ts +61 -0
  27. package/lib/typescript/src/specs/LLM.nitro.d.ts.map +1 -0
  28. package/lib/typescript/src/specs/ModelManager.nitro.d.ts +41 -0
  29. package/lib/typescript/src/specs/ModelManager.nitro.d.ts.map +1 -0
  30. package/nitrogen/generated/.gitattributes +1 -0
  31. package/nitrogen/generated/ios/MLXReactNative+autolinking.rb +60 -0
  32. package/nitrogen/generated/ios/MLXReactNative-Swift-Cxx-Bridge.cpp +98 -0
  33. package/nitrogen/generated/ios/MLXReactNative-Swift-Cxx-Bridge.hpp +312 -0
  34. package/nitrogen/generated/ios/MLXReactNative-Swift-Cxx-Umbrella.hpp +55 -0
  35. package/nitrogen/generated/ios/MLXReactNativeAutolinking.mm +41 -0
  36. package/nitrogen/generated/ios/MLXReactNativeAutolinking.swift +40 -0
  37. package/nitrogen/generated/ios/c++/HybridLLMSpecSwift.cpp +11 -0
  38. package/nitrogen/generated/ios/c++/HybridLLMSpecSwift.hpp +132 -0
  39. package/nitrogen/generated/ios/c++/HybridModelManagerSpecSwift.cpp +11 -0
  40. package/nitrogen/generated/ios/c++/HybridModelManagerSpecSwift.hpp +116 -0
  41. package/nitrogen/generated/ios/swift/Func_void.swift +47 -0
  42. package/nitrogen/generated/ios/swift/Func_void_bool.swift +47 -0
  43. package/nitrogen/generated/ios/swift/Func_void_double.swift +47 -0
  44. package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +47 -0
  45. package/nitrogen/generated/ios/swift/Func_void_std__string.swift +47 -0
  46. package/nitrogen/generated/ios/swift/Func_void_std__vector_std__string_.swift +47 -0
  47. package/nitrogen/generated/ios/swift/GenerationStats.swift +69 -0
  48. package/nitrogen/generated/ios/swift/HybridLLMSpec.swift +64 -0
  49. package/nitrogen/generated/ios/swift/HybridLLMSpec_cxx.swift +250 -0
  50. package/nitrogen/generated/ios/swift/HybridModelManagerSpec.swift +60 -0
  51. package/nitrogen/generated/ios/swift/HybridModelManagerSpec_cxx.swift +234 -0
  52. package/nitrogen/generated/shared/c++/GenerationStats.hpp +87 -0
  53. package/nitrogen/generated/shared/c++/HybridLLMSpec.cpp +32 -0
  54. package/nitrogen/generated/shared/c++/HybridLLMSpec.hpp +76 -0
  55. package/nitrogen/generated/shared/c++/HybridModelManagerSpec.cpp +27 -0
  56. package/nitrogen/generated/shared/c++/HybridModelManagerSpec.hpp +70 -0
  57. package/package.json +96 -0
  58. package/src/index.ts +6 -0
  59. package/src/llm.ts +116 -0
  60. package/src/modelManager.ts +88 -0
  61. package/src/models.ts +45 -0
  62. package/src/specs/LLM.nitro.ts +66 -0
  63. package/src/specs/ModelManager.nitro.ts +44 -0
@@ -0,0 +1,250 @@
1
+ ///
2
+ /// HybridLLMSpec_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
+
11
+ /**
12
+ * A class implementation that bridges HybridLLMSpec over to C++.
13
+ * In C++, we cannot use Swift protocols - so we need to wrap it in a class to make it strongly defined.
14
+ *
15
+ * Also, some Swift types need to be bridged with special handling:
16
+ * - Enums need to be wrapped in Structs, otherwise they cannot be accessed bi-directionally (Swift bug: https://github.com/swiftlang/swift/issues/75330)
17
+ * - Other HybridObjects need to be wrapped/unwrapped from the Swift TCxx wrapper
18
+ * - Throwing methods need to be wrapped with a Result<T, Error> type, as exceptions cannot be propagated to C++
19
+ */
20
+ open class HybridLLMSpec_cxx {
21
+ /**
22
+ * The Swift <> C++ bridge's namespace (`margelo::nitro::mlxreactnative::bridge::swift`)
23
+ * from `MLXReactNative-Swift-Cxx-Bridge.hpp`.
24
+ * This contains specialized C++ templates, and C++ helper functions that can be accessed from Swift.
25
+ */
26
+ public typealias bridge = margelo.nitro.mlxreactnative.bridge.swift
27
+
28
+ /**
29
+ * Holds an instance of the `HybridLLMSpec` Swift protocol.
30
+ */
31
+ private var __implementation: any HybridLLMSpec
32
+
33
+ /**
34
+ * Holds a weak pointer to the C++ class that wraps the Swift class.
35
+ */
36
+ private var __cxxPart: bridge.std__weak_ptr_HybridLLMSpec_
37
+
38
+ /**
39
+ * Create a new `HybridLLMSpec_cxx` that wraps the given `HybridLLMSpec`.
40
+ * All properties and methods bridge to C++ types.
41
+ */
42
+ public init(_ implementation: any HybridLLMSpec) {
43
+ self.__implementation = implementation
44
+ self.__cxxPart = .init()
45
+ /* no base class */
46
+ }
47
+
48
+ /**
49
+ * Get the actual `HybridLLMSpec` instance this class wraps.
50
+ */
51
+ @inline(__always)
52
+ public func getHybridLLMSpec() -> any HybridLLMSpec {
53
+ return __implementation
54
+ }
55
+
56
+ /**
57
+ * Casts this instance to a retained unsafe raw pointer.
58
+ * This acquires one additional strong reference on the object!
59
+ */
60
+ public func toUnsafe() -> UnsafeMutableRawPointer {
61
+ return Unmanaged.passRetained(self).toOpaque()
62
+ }
63
+
64
+ /**
65
+ * Casts an unsafe pointer to a `HybridLLMSpec_cxx`.
66
+ * The pointer has to be a retained opaque `Unmanaged<HybridLLMSpec_cxx>`.
67
+ * This removes one strong reference from the object!
68
+ */
69
+ public class func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> HybridLLMSpec_cxx {
70
+ return Unmanaged<HybridLLMSpec_cxx>.fromOpaque(pointer).takeRetainedValue()
71
+ }
72
+
73
+ /**
74
+ * Gets (or creates) the C++ part of this Hybrid Object.
75
+ * The C++ part is a `std::shared_ptr<HybridLLMSpec>`.
76
+ */
77
+ public func getCxxPart() -> bridge.std__shared_ptr_HybridLLMSpec_ {
78
+ let cachedCxxPart = self.__cxxPart.lock()
79
+ if Bool(fromCxx: cachedCxxPart) {
80
+ return cachedCxxPart
81
+ } else {
82
+ let newCxxPart = bridge.create_std__shared_ptr_HybridLLMSpec_(self.toUnsafe())
83
+ __cxxPart = bridge.weakify_std__shared_ptr_HybridLLMSpec_(newCxxPart)
84
+ return newCxxPart
85
+ }
86
+ }
87
+
88
+
89
+
90
+ /**
91
+ * Get the memory size of the Swift class (plus size of any other allocations)
92
+ * so the JS VM can properly track it and garbage-collect the JS object if needed.
93
+ */
94
+ @inline(__always)
95
+ public var memorySize: Int {
96
+ return MemoryHelper.getSizeOf(self.__implementation) + self.__implementation.memorySize
97
+ }
98
+
99
+ /**
100
+ * Call dispose() on the Swift class.
101
+ * This _may_ be called manually from JS.
102
+ */
103
+ @inline(__always)
104
+ public func dispose() {
105
+ self.__implementation.dispose()
106
+ }
107
+
108
+ /**
109
+ * Call toString() on the Swift class.
110
+ */
111
+ @inline(__always)
112
+ public func toString() -> String {
113
+ return self.__implementation.toString()
114
+ }
115
+
116
+ // Properties
117
+ public final var isLoaded: Bool {
118
+ @inline(__always)
119
+ get {
120
+ return self.__implementation.isLoaded
121
+ }
122
+ }
123
+
124
+ public final var isGenerating: Bool {
125
+ @inline(__always)
126
+ get {
127
+ return self.__implementation.isGenerating
128
+ }
129
+ }
130
+
131
+ public final var modelId: std.string {
132
+ @inline(__always)
133
+ get {
134
+ return std.string(self.__implementation.modelId)
135
+ }
136
+ }
137
+
138
+ public final var debug: Bool {
139
+ @inline(__always)
140
+ get {
141
+ return self.__implementation.debug
142
+ }
143
+ @inline(__always)
144
+ set {
145
+ self.__implementation.debug = newValue
146
+ }
147
+ }
148
+
149
+ public final var systemPrompt: std.string {
150
+ @inline(__always)
151
+ get {
152
+ return std.string(self.__implementation.systemPrompt)
153
+ }
154
+ @inline(__always)
155
+ set {
156
+ self.__implementation.systemPrompt = String(newValue)
157
+ }
158
+ }
159
+
160
+ // Methods
161
+ @inline(__always)
162
+ public final func load(modelId: std.string, onProgress: bridge.Func_void_double) -> bridge.Result_std__shared_ptr_Promise_void___ {
163
+ do {
164
+ let __result = try self.__implementation.load(modelId: String(modelId), onProgress: { () -> (Double) -> Void in
165
+ let __wrappedFunction = bridge.wrap_Func_void_double(onProgress)
166
+ return { (__progress: Double) -> Void in
167
+ __wrappedFunction.call(__progress)
168
+ }
169
+ }())
170
+ let __resultCpp = { () -> bridge.std__shared_ptr_Promise_void__ in
171
+ let __promise = bridge.create_std__shared_ptr_Promise_void__()
172
+ let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_void__(__promise)
173
+ __result
174
+ .then({ __result in __promiseHolder.resolve() })
175
+ .catch({ __error in __promiseHolder.reject(__error.toCpp()) })
176
+ return __promise
177
+ }()
178
+ return bridge.create_Result_std__shared_ptr_Promise_void___(__resultCpp)
179
+ } catch (let __error) {
180
+ let __exceptionPtr = __error.toCpp()
181
+ return bridge.create_Result_std__shared_ptr_Promise_void___(__exceptionPtr)
182
+ }
183
+ }
184
+
185
+ @inline(__always)
186
+ public final func generate(prompt: std.string) -> bridge.Result_std__shared_ptr_Promise_std__string___ {
187
+ do {
188
+ let __result = try self.__implementation.generate(prompt: String(prompt))
189
+ let __resultCpp = { () -> bridge.std__shared_ptr_Promise_std__string__ in
190
+ let __promise = bridge.create_std__shared_ptr_Promise_std__string__()
191
+ let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__string__(__promise)
192
+ __result
193
+ .then({ __result in __promiseHolder.resolve(std.string(__result)) })
194
+ .catch({ __error in __promiseHolder.reject(__error.toCpp()) })
195
+ return __promise
196
+ }()
197
+ return bridge.create_Result_std__shared_ptr_Promise_std__string___(__resultCpp)
198
+ } catch (let __error) {
199
+ let __exceptionPtr = __error.toCpp()
200
+ return bridge.create_Result_std__shared_ptr_Promise_std__string___(__exceptionPtr)
201
+ }
202
+ }
203
+
204
+ @inline(__always)
205
+ public final func stream(prompt: std.string, onToken: bridge.Func_void_std__string) -> bridge.Result_std__shared_ptr_Promise_std__string___ {
206
+ do {
207
+ let __result = try self.__implementation.stream(prompt: String(prompt), onToken: { () -> (String) -> Void in
208
+ let __wrappedFunction = bridge.wrap_Func_void_std__string(onToken)
209
+ return { (__token: String) -> Void in
210
+ __wrappedFunction.call(std.string(__token))
211
+ }
212
+ }())
213
+ let __resultCpp = { () -> bridge.std__shared_ptr_Promise_std__string__ in
214
+ let __promise = bridge.create_std__shared_ptr_Promise_std__string__()
215
+ let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__string__(__promise)
216
+ __result
217
+ .then({ __result in __promiseHolder.resolve(std.string(__result)) })
218
+ .catch({ __error in __promiseHolder.reject(__error.toCpp()) })
219
+ return __promise
220
+ }()
221
+ return bridge.create_Result_std__shared_ptr_Promise_std__string___(__resultCpp)
222
+ } catch (let __error) {
223
+ let __exceptionPtr = __error.toCpp()
224
+ return bridge.create_Result_std__shared_ptr_Promise_std__string___(__exceptionPtr)
225
+ }
226
+ }
227
+
228
+ @inline(__always)
229
+ public final func stop() -> bridge.Result_void_ {
230
+ do {
231
+ try self.__implementation.stop()
232
+ return bridge.create_Result_void_()
233
+ } catch (let __error) {
234
+ let __exceptionPtr = __error.toCpp()
235
+ return bridge.create_Result_void_(__exceptionPtr)
236
+ }
237
+ }
238
+
239
+ @inline(__always)
240
+ public final func getLastGenerationStats() -> bridge.Result_GenerationStats_ {
241
+ do {
242
+ let __result = try self.__implementation.getLastGenerationStats()
243
+ let __resultCpp = __result
244
+ return bridge.create_Result_GenerationStats_(__resultCpp)
245
+ } catch (let __error) {
246
+ let __exceptionPtr = __error.toCpp()
247
+ return bridge.create_Result_GenerationStats_(__exceptionPtr)
248
+ }
249
+ }
250
+ }
@@ -0,0 +1,60 @@
1
+ ///
2
+ /// HybridModelManagerSpec.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
+
11
+ /// See ``HybridModelManagerSpec``
12
+ public protocol HybridModelManagerSpec_protocol: HybridObject {
13
+ // Properties
14
+ var debug: Bool { get set }
15
+
16
+ // Methods
17
+ func download(modelId: String, progressCallback: @escaping (_ progress: Double) -> Void) throws -> Promise<String>
18
+ func isDownloaded(modelId: String) throws -> Promise<Bool>
19
+ func getDownloadedModels() throws -> Promise<[String]>
20
+ func deleteModel(modelId: String) throws -> Promise<Void>
21
+ func getModelPath(modelId: String) throws -> Promise<String>
22
+ }
23
+
24
+ public extension HybridModelManagerSpec_protocol {
25
+ /// Default implementation of ``HybridObject.toString``
26
+ func toString() -> String {
27
+ return "[HybridObject ModelManager]"
28
+ }
29
+ }
30
+
31
+ /// See ``HybridModelManagerSpec``
32
+ open class HybridModelManagerSpec_base {
33
+ private weak var cxxWrapper: HybridModelManagerSpec_cxx? = nil
34
+ public init() { }
35
+ public func getCxxWrapper() -> HybridModelManagerSpec_cxx {
36
+ #if DEBUG
37
+ guard self is HybridModelManagerSpec else {
38
+ fatalError("`self` is not a `HybridModelManagerSpec`! Did you accidentally inherit from `HybridModelManagerSpec_base` instead of `HybridModelManagerSpec`?")
39
+ }
40
+ #endif
41
+ if let cxxWrapper = self.cxxWrapper {
42
+ return cxxWrapper
43
+ } else {
44
+ let cxxWrapper = HybridModelManagerSpec_cxx(self as! HybridModelManagerSpec)
45
+ self.cxxWrapper = cxxWrapper
46
+ return cxxWrapper
47
+ }
48
+ }
49
+ }
50
+
51
+ /**
52
+ * A Swift base-protocol representing the ModelManager HybridObject.
53
+ * Implement this protocol to create Swift-based instances of ModelManager.
54
+ * ```swift
55
+ * class HybridModelManager : HybridModelManagerSpec {
56
+ * // ...
57
+ * }
58
+ * ```
59
+ */
60
+ public typealias HybridModelManagerSpec = HybridModelManagerSpec_protocol & HybridModelManagerSpec_base
@@ -0,0 +1,234 @@
1
+ ///
2
+ /// HybridModelManagerSpec_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
+
11
+ /**
12
+ * A class implementation that bridges HybridModelManagerSpec over to C++.
13
+ * In C++, we cannot use Swift protocols - so we need to wrap it in a class to make it strongly defined.
14
+ *
15
+ * Also, some Swift types need to be bridged with special handling:
16
+ * - Enums need to be wrapped in Structs, otherwise they cannot be accessed bi-directionally (Swift bug: https://github.com/swiftlang/swift/issues/75330)
17
+ * - Other HybridObjects need to be wrapped/unwrapped from the Swift TCxx wrapper
18
+ * - Throwing methods need to be wrapped with a Result<T, Error> type, as exceptions cannot be propagated to C++
19
+ */
20
+ open class HybridModelManagerSpec_cxx {
21
+ /**
22
+ * The Swift <> C++ bridge's namespace (`margelo::nitro::mlxreactnative::bridge::swift`)
23
+ * from `MLXReactNative-Swift-Cxx-Bridge.hpp`.
24
+ * This contains specialized C++ templates, and C++ helper functions that can be accessed from Swift.
25
+ */
26
+ public typealias bridge = margelo.nitro.mlxreactnative.bridge.swift
27
+
28
+ /**
29
+ * Holds an instance of the `HybridModelManagerSpec` Swift protocol.
30
+ */
31
+ private var __implementation: any HybridModelManagerSpec
32
+
33
+ /**
34
+ * Holds a weak pointer to the C++ class that wraps the Swift class.
35
+ */
36
+ private var __cxxPart: bridge.std__weak_ptr_HybridModelManagerSpec_
37
+
38
+ /**
39
+ * Create a new `HybridModelManagerSpec_cxx` that wraps the given `HybridModelManagerSpec`.
40
+ * All properties and methods bridge to C++ types.
41
+ */
42
+ public init(_ implementation: any HybridModelManagerSpec) {
43
+ self.__implementation = implementation
44
+ self.__cxxPart = .init()
45
+ /* no base class */
46
+ }
47
+
48
+ /**
49
+ * Get the actual `HybridModelManagerSpec` instance this class wraps.
50
+ */
51
+ @inline(__always)
52
+ public func getHybridModelManagerSpec() -> any HybridModelManagerSpec {
53
+ return __implementation
54
+ }
55
+
56
+ /**
57
+ * Casts this instance to a retained unsafe raw pointer.
58
+ * This acquires one additional strong reference on the object!
59
+ */
60
+ public func toUnsafe() -> UnsafeMutableRawPointer {
61
+ return Unmanaged.passRetained(self).toOpaque()
62
+ }
63
+
64
+ /**
65
+ * Casts an unsafe pointer to a `HybridModelManagerSpec_cxx`.
66
+ * The pointer has to be a retained opaque `Unmanaged<HybridModelManagerSpec_cxx>`.
67
+ * This removes one strong reference from the object!
68
+ */
69
+ public class func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> HybridModelManagerSpec_cxx {
70
+ return Unmanaged<HybridModelManagerSpec_cxx>.fromOpaque(pointer).takeRetainedValue()
71
+ }
72
+
73
+ /**
74
+ * Gets (or creates) the C++ part of this Hybrid Object.
75
+ * The C++ part is a `std::shared_ptr<HybridModelManagerSpec>`.
76
+ */
77
+ public func getCxxPart() -> bridge.std__shared_ptr_HybridModelManagerSpec_ {
78
+ let cachedCxxPart = self.__cxxPart.lock()
79
+ if Bool(fromCxx: cachedCxxPart) {
80
+ return cachedCxxPart
81
+ } else {
82
+ let newCxxPart = bridge.create_std__shared_ptr_HybridModelManagerSpec_(self.toUnsafe())
83
+ __cxxPart = bridge.weakify_std__shared_ptr_HybridModelManagerSpec_(newCxxPart)
84
+ return newCxxPart
85
+ }
86
+ }
87
+
88
+
89
+
90
+ /**
91
+ * Get the memory size of the Swift class (plus size of any other allocations)
92
+ * so the JS VM can properly track it and garbage-collect the JS object if needed.
93
+ */
94
+ @inline(__always)
95
+ public var memorySize: Int {
96
+ return MemoryHelper.getSizeOf(self.__implementation) + self.__implementation.memorySize
97
+ }
98
+
99
+ /**
100
+ * Call dispose() on the Swift class.
101
+ * This _may_ be called manually from JS.
102
+ */
103
+ @inline(__always)
104
+ public func dispose() {
105
+ self.__implementation.dispose()
106
+ }
107
+
108
+ /**
109
+ * Call toString() on the Swift class.
110
+ */
111
+ @inline(__always)
112
+ public func toString() -> String {
113
+ return self.__implementation.toString()
114
+ }
115
+
116
+ // Properties
117
+ public final var debug: Bool {
118
+ @inline(__always)
119
+ get {
120
+ return self.__implementation.debug
121
+ }
122
+ @inline(__always)
123
+ set {
124
+ self.__implementation.debug = newValue
125
+ }
126
+ }
127
+
128
+ // Methods
129
+ @inline(__always)
130
+ public final func download(modelId: std.string, progressCallback: bridge.Func_void_double) -> bridge.Result_std__shared_ptr_Promise_std__string___ {
131
+ do {
132
+ let __result = try self.__implementation.download(modelId: String(modelId), progressCallback: { () -> (Double) -> Void in
133
+ let __wrappedFunction = bridge.wrap_Func_void_double(progressCallback)
134
+ return { (__progress: Double) -> Void in
135
+ __wrappedFunction.call(__progress)
136
+ }
137
+ }())
138
+ let __resultCpp = { () -> bridge.std__shared_ptr_Promise_std__string__ in
139
+ let __promise = bridge.create_std__shared_ptr_Promise_std__string__()
140
+ let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__string__(__promise)
141
+ __result
142
+ .then({ __result in __promiseHolder.resolve(std.string(__result)) })
143
+ .catch({ __error in __promiseHolder.reject(__error.toCpp()) })
144
+ return __promise
145
+ }()
146
+ return bridge.create_Result_std__shared_ptr_Promise_std__string___(__resultCpp)
147
+ } catch (let __error) {
148
+ let __exceptionPtr = __error.toCpp()
149
+ return bridge.create_Result_std__shared_ptr_Promise_std__string___(__exceptionPtr)
150
+ }
151
+ }
152
+
153
+ @inline(__always)
154
+ public final func isDownloaded(modelId: std.string) -> bridge.Result_std__shared_ptr_Promise_bool___ {
155
+ do {
156
+ let __result = try self.__implementation.isDownloaded(modelId: String(modelId))
157
+ let __resultCpp = { () -> bridge.std__shared_ptr_Promise_bool__ in
158
+ let __promise = bridge.create_std__shared_ptr_Promise_bool__()
159
+ let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_bool__(__promise)
160
+ __result
161
+ .then({ __result in __promiseHolder.resolve(__result) })
162
+ .catch({ __error in __promiseHolder.reject(__error.toCpp()) })
163
+ return __promise
164
+ }()
165
+ return bridge.create_Result_std__shared_ptr_Promise_bool___(__resultCpp)
166
+ } catch (let __error) {
167
+ let __exceptionPtr = __error.toCpp()
168
+ return bridge.create_Result_std__shared_ptr_Promise_bool___(__exceptionPtr)
169
+ }
170
+ }
171
+
172
+ @inline(__always)
173
+ public final func getDownloadedModels() -> bridge.Result_std__shared_ptr_Promise_std__vector_std__string____ {
174
+ do {
175
+ let __result = try self.__implementation.getDownloadedModels()
176
+ let __resultCpp = { () -> bridge.std__shared_ptr_Promise_std__vector_std__string___ in
177
+ let __promise = bridge.create_std__shared_ptr_Promise_std__vector_std__string___()
178
+ let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__vector_std__string___(__promise)
179
+ __result
180
+ .then({ __result in __promiseHolder.resolve({ () -> bridge.std__vector_std__string_ in
181
+ var __vector = bridge.create_std__vector_std__string_(__result.count)
182
+ for __item in __result {
183
+ __vector.push_back(std.string(__item))
184
+ }
185
+ return __vector
186
+ }()) })
187
+ .catch({ __error in __promiseHolder.reject(__error.toCpp()) })
188
+ return __promise
189
+ }()
190
+ return bridge.create_Result_std__shared_ptr_Promise_std__vector_std__string____(__resultCpp)
191
+ } catch (let __error) {
192
+ let __exceptionPtr = __error.toCpp()
193
+ return bridge.create_Result_std__shared_ptr_Promise_std__vector_std__string____(__exceptionPtr)
194
+ }
195
+ }
196
+
197
+ @inline(__always)
198
+ public final func deleteModel(modelId: std.string) -> bridge.Result_std__shared_ptr_Promise_void___ {
199
+ do {
200
+ let __result = try self.__implementation.deleteModel(modelId: String(modelId))
201
+ let __resultCpp = { () -> bridge.std__shared_ptr_Promise_void__ in
202
+ let __promise = bridge.create_std__shared_ptr_Promise_void__()
203
+ let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_void__(__promise)
204
+ __result
205
+ .then({ __result in __promiseHolder.resolve() })
206
+ .catch({ __error in __promiseHolder.reject(__error.toCpp()) })
207
+ return __promise
208
+ }()
209
+ return bridge.create_Result_std__shared_ptr_Promise_void___(__resultCpp)
210
+ } catch (let __error) {
211
+ let __exceptionPtr = __error.toCpp()
212
+ return bridge.create_Result_std__shared_ptr_Promise_void___(__exceptionPtr)
213
+ }
214
+ }
215
+
216
+ @inline(__always)
217
+ public final func getModelPath(modelId: std.string) -> bridge.Result_std__shared_ptr_Promise_std__string___ {
218
+ do {
219
+ let __result = try self.__implementation.getModelPath(modelId: String(modelId))
220
+ let __resultCpp = { () -> bridge.std__shared_ptr_Promise_std__string__ in
221
+ let __promise = bridge.create_std__shared_ptr_Promise_std__string__()
222
+ let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__string__(__promise)
223
+ __result
224
+ .then({ __result in __promiseHolder.resolve(std.string(__result)) })
225
+ .catch({ __error in __promiseHolder.reject(__error.toCpp()) })
226
+ return __promise
227
+ }()
228
+ return bridge.create_Result_std__shared_ptr_Promise_std__string___(__resultCpp)
229
+ } catch (let __error) {
230
+ let __exceptionPtr = __error.toCpp()
231
+ return bridge.create_Result_std__shared_ptr_Promise_std__string___(__exceptionPtr)
232
+ }
233
+ }
234
+ }
@@ -0,0 +1,87 @@
1
+ ///
2
+ /// GenerationStats.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/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
+
29
+
30
+ namespace margelo::nitro::mlxreactnative {
31
+
32
+ /**
33
+ * A struct which can be represented as a JavaScript object (GenerationStats).
34
+ */
35
+ struct GenerationStats {
36
+ public:
37
+ double tokenCount SWIFT_PRIVATE;
38
+ double tokensPerSecond SWIFT_PRIVATE;
39
+ double timeToFirstToken SWIFT_PRIVATE;
40
+ double totalTime SWIFT_PRIVATE;
41
+
42
+ public:
43
+ GenerationStats() = default;
44
+ explicit GenerationStats(double tokenCount, double tokensPerSecond, double timeToFirstToken, double totalTime): tokenCount(tokenCount), tokensPerSecond(tokensPerSecond), timeToFirstToken(timeToFirstToken), totalTime(totalTime) {}
45
+ };
46
+
47
+ } // namespace margelo::nitro::mlxreactnative
48
+
49
+ namespace margelo::nitro {
50
+
51
+ // C++ GenerationStats <> JS GenerationStats (object)
52
+ template <>
53
+ struct JSIConverter<margelo::nitro::mlxreactnative::GenerationStats> final {
54
+ static inline margelo::nitro::mlxreactnative::GenerationStats fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
55
+ jsi::Object obj = arg.asObject(runtime);
56
+ return margelo::nitro::mlxreactnative::GenerationStats(
57
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, "tokenCount")),
58
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, "tokensPerSecond")),
59
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, "timeToFirstToken")),
60
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, "totalTime"))
61
+ );
62
+ }
63
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::mlxreactnative::GenerationStats& arg) {
64
+ jsi::Object obj(runtime);
65
+ obj.setProperty(runtime, "tokenCount", JSIConverter<double>::toJSI(runtime, arg.tokenCount));
66
+ obj.setProperty(runtime, "tokensPerSecond", JSIConverter<double>::toJSI(runtime, arg.tokensPerSecond));
67
+ obj.setProperty(runtime, "timeToFirstToken", JSIConverter<double>::toJSI(runtime, arg.timeToFirstToken));
68
+ obj.setProperty(runtime, "totalTime", JSIConverter<double>::toJSI(runtime, arg.totalTime));
69
+ return obj;
70
+ }
71
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
72
+ if (!value.isObject()) {
73
+ return false;
74
+ }
75
+ jsi::Object obj = value.getObject(runtime);
76
+ if (!nitro::isPlainObject(runtime, obj)) {
77
+ return false;
78
+ }
79
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, "tokenCount"))) return false;
80
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, "tokensPerSecond"))) return false;
81
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, "timeToFirstToken"))) return false;
82
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, "totalTime"))) return false;
83
+ return true;
84
+ }
85
+ };
86
+
87
+ } // namespace margelo::nitro
@@ -0,0 +1,32 @@
1
+ ///
2
+ /// HybridLLMSpec.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 "HybridLLMSpec.hpp"
9
+
10
+ namespace margelo::nitro::mlxreactnative {
11
+
12
+ void HybridLLMSpec::loadHybridMethods() {
13
+ // load base methods/properties
14
+ HybridObject::loadHybridMethods();
15
+ // load custom methods/properties
16
+ registerHybrids(this, [](Prototype& prototype) {
17
+ prototype.registerHybridGetter("isLoaded", &HybridLLMSpec::getIsLoaded);
18
+ prototype.registerHybridGetter("isGenerating", &HybridLLMSpec::getIsGenerating);
19
+ prototype.registerHybridGetter("modelId", &HybridLLMSpec::getModelId);
20
+ prototype.registerHybridGetter("debug", &HybridLLMSpec::getDebug);
21
+ prototype.registerHybridSetter("debug", &HybridLLMSpec::setDebug);
22
+ prototype.registerHybridGetter("systemPrompt", &HybridLLMSpec::getSystemPrompt);
23
+ prototype.registerHybridSetter("systemPrompt", &HybridLLMSpec::setSystemPrompt);
24
+ prototype.registerHybridMethod("load", &HybridLLMSpec::load);
25
+ prototype.registerHybridMethod("generate", &HybridLLMSpec::generate);
26
+ prototype.registerHybridMethod("stream", &HybridLLMSpec::stream);
27
+ prototype.registerHybridMethod("stop", &HybridLLMSpec::stop);
28
+ prototype.registerHybridMethod("getLastGenerationStats", &HybridLLMSpec::getLastGenerationStats);
29
+ });
30
+ }
31
+
32
+ } // namespace margelo::nitro::mlxreactnative