react-native-nitro-mlx 0.2.2 → 0.3.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 (59) hide show
  1. package/MLXReactNative.podspec +1 -1
  2. package/ios/Sources/HybridLLM.swift +250 -15
  3. package/lib/module/index.js +1 -0
  4. package/lib/module/index.js.map +1 -1
  5. package/lib/module/llm.js +33 -3
  6. package/lib/module/llm.js.map +1 -1
  7. package/lib/module/tool-utils.js +56 -0
  8. package/lib/module/tool-utils.js.map +1 -0
  9. package/lib/typescript/src/index.d.ts +3 -2
  10. package/lib/typescript/src/index.d.ts.map +1 -1
  11. package/lib/typescript/src/llm.d.ts +14 -2
  12. package/lib/typescript/src/llm.d.ts.map +1 -1
  13. package/lib/typescript/src/specs/LLM.nitro.d.ts +30 -3
  14. package/lib/typescript/src/specs/LLM.nitro.d.ts.map +1 -1
  15. package/lib/typescript/src/tool-utils.d.ts +13 -0
  16. package/lib/typescript/src/tool-utils.d.ts.map +1 -0
  17. package/nitrogen/generated/ios/MLXReactNative+autolinking.rb +1 -1
  18. package/nitrogen/generated/ios/MLXReactNative-Swift-Cxx-Bridge.cpp +34 -1
  19. package/nitrogen/generated/ios/MLXReactNative-Swift-Cxx-Bridge.hpp +173 -1
  20. package/nitrogen/generated/ios/MLXReactNative-Swift-Cxx-Umbrella.hpp +8 -1
  21. package/nitrogen/generated/ios/MLXReactNativeAutolinking.mm +1 -1
  22. package/nitrogen/generated/ios/MLXReactNativeAutolinking.swift +1 -1
  23. package/nitrogen/generated/ios/c++/HybridLLMSpecSwift.cpp +1 -1
  24. package/nitrogen/generated/ios/c++/HybridLLMSpecSwift.hpp +10 -3
  25. package/nitrogen/generated/ios/c++/HybridModelManagerSpecSwift.cpp +1 -1
  26. package/nitrogen/generated/ios/c++/HybridModelManagerSpecSwift.hpp +1 -1
  27. package/nitrogen/generated/ios/swift/Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_AnyMap______std__shared_ptr_AnyMap_.swift +62 -0
  28. package/nitrogen/generated/ios/swift/Func_void.swift +1 -1
  29. package/nitrogen/generated/ios/swift/Func_void_bool.swift +1 -1
  30. package/nitrogen/generated/ios/swift/Func_void_double.swift +1 -1
  31. package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +1 -1
  32. package/nitrogen/generated/ios/swift/Func_void_std__shared_ptr_AnyMap_.swift +47 -0
  33. package/nitrogen/generated/ios/swift/Func_void_std__shared_ptr_Promise_std__shared_ptr_AnyMap___.swift +67 -0
  34. package/nitrogen/generated/ios/swift/Func_void_std__string.swift +1 -1
  35. package/nitrogen/generated/ios/swift/Func_void_std__string_std__string.swift +47 -0
  36. package/nitrogen/generated/ios/swift/Func_void_std__vector_std__string_.swift +1 -1
  37. package/nitrogen/generated/ios/swift/GenerationStats.swift +1 -1
  38. package/nitrogen/generated/ios/swift/HybridLLMSpec.swift +2 -2
  39. package/nitrogen/generated/ios/swift/HybridLLMSpec_cxx.swift +14 -2
  40. package/nitrogen/generated/ios/swift/HybridModelManagerSpec.swift +1 -1
  41. package/nitrogen/generated/ios/swift/HybridModelManagerSpec_cxx.swift +1 -1
  42. package/nitrogen/generated/ios/swift/LLMLoadOptions.swift +44 -2
  43. package/nitrogen/generated/ios/swift/LLMMessage.swift +1 -1
  44. package/nitrogen/generated/ios/swift/ToolDefinition.swift +113 -0
  45. package/nitrogen/generated/ios/swift/ToolParameter.swift +69 -0
  46. package/nitrogen/generated/shared/c++/GenerationStats.hpp +1 -1
  47. package/nitrogen/generated/shared/c++/HybridLLMSpec.cpp +1 -1
  48. package/nitrogen/generated/shared/c++/HybridLLMSpec.hpp +2 -2
  49. package/nitrogen/generated/shared/c++/HybridModelManagerSpec.cpp +1 -1
  50. package/nitrogen/generated/shared/c++/HybridModelManagerSpec.hpp +1 -1
  51. package/nitrogen/generated/shared/c++/LLMLoadOptions.hpp +10 -3
  52. package/nitrogen/generated/shared/c++/LLMMessage.hpp +1 -1
  53. package/nitrogen/generated/shared/c++/ToolDefinition.hpp +93 -0
  54. package/nitrogen/generated/shared/c++/ToolParameter.hpp +87 -0
  55. package/package.json +8 -7
  56. package/src/index.ts +10 -3
  57. package/src/llm.ts +42 -3
  58. package/src/specs/LLM.nitro.ts +37 -3
  59. package/src/tool-utils.ts +74 -0
@@ -2,7 +2,7 @@
2
2
  /// MLXReactNative-Swift-Cxx-Bridge.cpp
3
3
  /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
4
  /// https://github.com/mrousavy/nitro
5
- /// Copyright © 2025 Marc Rousavy @ Margelo
5
+ /// Copyright © 2026 Marc Rousavy @ Margelo
6
6
  ///
7
7
 
8
8
  #include "MLXReactNative-Swift-Cxx-Bridge.hpp"
@@ -39,6 +39,31 @@ namespace margelo::nitro::mlxreactnative::bridge::swift {
39
39
  };
40
40
  }
41
41
 
42
+ // pragma MARK: std::function<void(const std::shared_ptr<AnyMap>& /* result */)>
43
+ Func_void_std__shared_ptr_AnyMap_ create_Func_void_std__shared_ptr_AnyMap_(void* NON_NULL swiftClosureWrapper) noexcept {
44
+ auto swiftClosure = MLXReactNative::Func_void_std__shared_ptr_AnyMap_::fromUnsafe(swiftClosureWrapper);
45
+ return [swiftClosure = std::move(swiftClosure)](const std::shared_ptr<AnyMap>& result) mutable -> void {
46
+ swiftClosure.call(result);
47
+ };
48
+ }
49
+
50
+ // pragma MARK: std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::shared_ptr<AnyMap>>>>>(const std::shared_ptr<AnyMap>& /* args */)>
51
+ Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_AnyMap______std__shared_ptr_AnyMap_ create_Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_AnyMap______std__shared_ptr_AnyMap_(void* NON_NULL swiftClosureWrapper) noexcept {
52
+ auto swiftClosure = MLXReactNative::Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_AnyMap______std__shared_ptr_AnyMap_::fromUnsafe(swiftClosureWrapper);
53
+ return [swiftClosure = std::move(swiftClosure)](const std::shared_ptr<AnyMap>& args) mutable -> std::shared_ptr<Promise<std::shared_ptr<Promise<std::shared_ptr<AnyMap>>>>> {
54
+ auto __result = swiftClosure.call(args);
55
+ return __result;
56
+ };
57
+ }
58
+
59
+ // pragma MARK: std::function<void(const std::shared_ptr<Promise<std::shared_ptr<AnyMap>>>& /* result */)>
60
+ Func_void_std__shared_ptr_Promise_std__shared_ptr_AnyMap___ create_Func_void_std__shared_ptr_Promise_std__shared_ptr_AnyMap___(void* NON_NULL swiftClosureWrapper) noexcept {
61
+ auto swiftClosure = MLXReactNative::Func_void_std__shared_ptr_Promise_std__shared_ptr_AnyMap___::fromUnsafe(swiftClosureWrapper);
62
+ return [swiftClosure = std::move(swiftClosure)](const std::shared_ptr<Promise<std::shared_ptr<AnyMap>>>& result) mutable -> void {
63
+ swiftClosure.call(result);
64
+ };
65
+ }
66
+
42
67
  // pragma MARK: std::function<void(const std::string& /* result */)>
43
68
  Func_void_std__string create_Func_void_std__string(void* NON_NULL swiftClosureWrapper) noexcept {
44
69
  auto swiftClosure = MLXReactNative::Func_void_std__string::fromUnsafe(swiftClosureWrapper);
@@ -47,6 +72,14 @@ namespace margelo::nitro::mlxreactnative::bridge::swift {
47
72
  };
48
73
  }
49
74
 
75
+ // pragma MARK: std::function<void(const std::string& /* toolName */, const std::string& /* args */)>
76
+ Func_void_std__string_std__string create_Func_void_std__string_std__string(void* NON_NULL swiftClosureWrapper) noexcept {
77
+ auto swiftClosure = MLXReactNative::Func_void_std__string_std__string::fromUnsafe(swiftClosureWrapper);
78
+ return [swiftClosure = std::move(swiftClosure)](const std::string& toolName, const std::string& args) mutable -> void {
79
+ swiftClosure.call(toolName, args);
80
+ };
81
+ }
82
+
50
83
  // pragma MARK: std::shared_ptr<HybridLLMSpec>
51
84
  std::shared_ptr<HybridLLMSpec> create_std__shared_ptr_HybridLLMSpec_(void* NON_NULL swiftUnsafePointer) noexcept {
52
85
  MLXReactNative::HybridLLMSpec_cxx swiftPart = MLXReactNative::HybridLLMSpec_cxx::fromUnsafe(swiftUnsafePointer);
@@ -2,7 +2,7 @@
2
2
  /// MLXReactNative-Swift-Cxx-Bridge.hpp
3
3
  /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
4
  /// https://github.com/mrousavy/nitro
5
- /// Copyright © 2025 Marc Rousavy @ Margelo
5
+ /// Copyright © 2026 Marc Rousavy @ Margelo
6
6
  ///
7
7
 
8
8
  #pragma once
@@ -18,6 +18,10 @@ namespace margelo::nitro::mlxreactnative { class HybridModelManagerSpec; }
18
18
  namespace margelo::nitro::mlxreactnative { struct LLMLoadOptions; }
19
19
  // Forward declaration of `LLMMessage` to properly resolve imports.
20
20
  namespace margelo::nitro::mlxreactnative { struct LLMMessage; }
21
+ // Forward declaration of `ToolDefinition` to properly resolve imports.
22
+ namespace margelo::nitro::mlxreactnative { struct ToolDefinition; }
23
+ // Forward declaration of `ToolParameter` to properly resolve imports.
24
+ namespace margelo::nitro::mlxreactnative { struct ToolParameter; }
21
25
 
22
26
  // Forward declarations of Swift defined types
23
27
  // Forward declaration of `HybridLLMSpec_cxx` to properly resolve imports.
@@ -31,6 +35,9 @@ namespace MLXReactNative { class HybridModelManagerSpec_cxx; }
31
35
  #include "HybridModelManagerSpec.hpp"
32
36
  #include "LLMLoadOptions.hpp"
33
37
  #include "LLMMessage.hpp"
38
+ #include "ToolDefinition.hpp"
39
+ #include "ToolParameter.hpp"
40
+ #include <NitroModules/AnyMap.hpp>
34
41
  #include <NitroModules/Promise.hpp>
35
42
  #include <NitroModules/PromiseHolder.hpp>
36
43
  #include <NitroModules/Result.hpp>
@@ -181,6 +188,134 @@ namespace margelo::nitro::mlxreactnative::bridge::swift {
181
188
  return *optional;
182
189
  }
183
190
 
191
+ // pragma MARK: std::vector<ToolParameter>
192
+ /**
193
+ * Specialized version of `std::vector<ToolParameter>`.
194
+ */
195
+ using std__vector_ToolParameter_ = std::vector<ToolParameter>;
196
+ inline std::vector<ToolParameter> create_std__vector_ToolParameter_(size_t size) noexcept {
197
+ std::vector<ToolParameter> vector;
198
+ vector.reserve(size);
199
+ return vector;
200
+ }
201
+
202
+ // pragma MARK: std::shared_ptr<Promise<std::shared_ptr<AnyMap>>>
203
+ /**
204
+ * Specialized version of `std::shared_ptr<Promise<std::shared_ptr<AnyMap>>>`.
205
+ */
206
+ using std__shared_ptr_Promise_std__shared_ptr_AnyMap___ = std::shared_ptr<Promise<std::shared_ptr<AnyMap>>>;
207
+ inline std::shared_ptr<Promise<std::shared_ptr<AnyMap>>> create_std__shared_ptr_Promise_std__shared_ptr_AnyMap___() noexcept {
208
+ return Promise<std::shared_ptr<AnyMap>>::create();
209
+ }
210
+ inline PromiseHolder<std::shared_ptr<AnyMap>> wrap_std__shared_ptr_Promise_std__shared_ptr_AnyMap___(std::shared_ptr<Promise<std::shared_ptr<AnyMap>>> promise) noexcept {
211
+ return PromiseHolder<std::shared_ptr<AnyMap>>(std::move(promise));
212
+ }
213
+
214
+ // pragma MARK: std::function<void(const std::shared_ptr<AnyMap>& /* result */)>
215
+ /**
216
+ * Specialized version of `std::function<void(const std::shared_ptr<AnyMap>&)>`.
217
+ */
218
+ using Func_void_std__shared_ptr_AnyMap_ = std::function<void(const std::shared_ptr<AnyMap>& /* result */)>;
219
+ /**
220
+ * Wrapper class for a `std::function<void(const std::shared_ptr<AnyMap>& / * result * /)>`, this can be used from Swift.
221
+ */
222
+ class Func_void_std__shared_ptr_AnyMap__Wrapper final {
223
+ public:
224
+ explicit Func_void_std__shared_ptr_AnyMap__Wrapper(std::function<void(const std::shared_ptr<AnyMap>& /* result */)>&& func): _function(std::make_unique<std::function<void(const std::shared_ptr<AnyMap>& /* result */)>>(std::move(func))) {}
225
+ inline void call(std::shared_ptr<AnyMap> result) const noexcept {
226
+ _function->operator()(result);
227
+ }
228
+ private:
229
+ std::unique_ptr<std::function<void(const std::shared_ptr<AnyMap>& /* result */)>> _function;
230
+ } SWIFT_NONCOPYABLE;
231
+ Func_void_std__shared_ptr_AnyMap_ create_Func_void_std__shared_ptr_AnyMap_(void* NON_NULL swiftClosureWrapper) noexcept;
232
+ inline Func_void_std__shared_ptr_AnyMap__Wrapper wrap_Func_void_std__shared_ptr_AnyMap_(Func_void_std__shared_ptr_AnyMap_ value) noexcept {
233
+ return Func_void_std__shared_ptr_AnyMap__Wrapper(std::move(value));
234
+ }
235
+
236
+ // pragma MARK: std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::shared_ptr<AnyMap>>>>>(const std::shared_ptr<AnyMap>& /* args */)>
237
+ /**
238
+ * Specialized version of `std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::shared_ptr<AnyMap>>>>>(const std::shared_ptr<AnyMap>&)>`.
239
+ */
240
+ using Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_AnyMap______std__shared_ptr_AnyMap_ = std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::shared_ptr<AnyMap>>>>>(const std::shared_ptr<AnyMap>& /* args */)>;
241
+ /**
242
+ * Wrapper class for a `std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::shared_ptr<AnyMap>>>>>(const std::shared_ptr<AnyMap>& / * args * /)>`, this can be used from Swift.
243
+ */
244
+ class Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_AnyMap______std__shared_ptr_AnyMap__Wrapper final {
245
+ public:
246
+ explicit Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_AnyMap______std__shared_ptr_AnyMap__Wrapper(std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::shared_ptr<AnyMap>>>>>(const std::shared_ptr<AnyMap>& /* args */)>&& func): _function(std::make_unique<std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::shared_ptr<AnyMap>>>>>(const std::shared_ptr<AnyMap>& /* args */)>>(std::move(func))) {}
247
+ inline std::shared_ptr<Promise<std::shared_ptr<Promise<std::shared_ptr<AnyMap>>>>> call(std::shared_ptr<AnyMap> args) const noexcept {
248
+ auto __result = _function->operator()(args);
249
+ return __result;
250
+ }
251
+ private:
252
+ std::unique_ptr<std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::shared_ptr<AnyMap>>>>>(const std::shared_ptr<AnyMap>& /* args */)>> _function;
253
+ } SWIFT_NONCOPYABLE;
254
+ Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_AnyMap______std__shared_ptr_AnyMap_ create_Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_AnyMap______std__shared_ptr_AnyMap_(void* NON_NULL swiftClosureWrapper) noexcept;
255
+ inline Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_AnyMap______std__shared_ptr_AnyMap__Wrapper wrap_Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_AnyMap______std__shared_ptr_AnyMap_(Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_AnyMap______std__shared_ptr_AnyMap_ value) noexcept {
256
+ return Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_AnyMap______std__shared_ptr_AnyMap__Wrapper(std::move(value));
257
+ }
258
+
259
+ // pragma MARK: std::shared_ptr<Promise<std::shared_ptr<Promise<std::shared_ptr<AnyMap>>>>>
260
+ /**
261
+ * Specialized version of `std::shared_ptr<Promise<std::shared_ptr<Promise<std::shared_ptr<AnyMap>>>>>`.
262
+ */
263
+ using std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_AnyMap_____ = std::shared_ptr<Promise<std::shared_ptr<Promise<std::shared_ptr<AnyMap>>>>>;
264
+ inline std::shared_ptr<Promise<std::shared_ptr<Promise<std::shared_ptr<AnyMap>>>>> create_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_AnyMap_____() noexcept {
265
+ return Promise<std::shared_ptr<Promise<std::shared_ptr<AnyMap>>>>::create();
266
+ }
267
+ inline PromiseHolder<std::shared_ptr<Promise<std::shared_ptr<AnyMap>>>> wrap_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_AnyMap_____(std::shared_ptr<Promise<std::shared_ptr<Promise<std::shared_ptr<AnyMap>>>>> promise) noexcept {
268
+ return PromiseHolder<std::shared_ptr<Promise<std::shared_ptr<AnyMap>>>>(std::move(promise));
269
+ }
270
+
271
+ // pragma MARK: std::function<void(const std::shared_ptr<Promise<std::shared_ptr<AnyMap>>>& /* result */)>
272
+ /**
273
+ * Specialized version of `std::function<void(const std::shared_ptr<Promise<std::shared_ptr<AnyMap>>>&)>`.
274
+ */
275
+ using Func_void_std__shared_ptr_Promise_std__shared_ptr_AnyMap___ = std::function<void(const std::shared_ptr<Promise<std::shared_ptr<AnyMap>>>& /* result */)>;
276
+ /**
277
+ * Wrapper class for a `std::function<void(const std::shared_ptr<Promise<std::shared_ptr<AnyMap>>>& / * result * /)>`, this can be used from Swift.
278
+ */
279
+ class Func_void_std__shared_ptr_Promise_std__shared_ptr_AnyMap____Wrapper final {
280
+ public:
281
+ explicit Func_void_std__shared_ptr_Promise_std__shared_ptr_AnyMap____Wrapper(std::function<void(const std::shared_ptr<Promise<std::shared_ptr<AnyMap>>>& /* result */)>&& func): _function(std::make_unique<std::function<void(const std::shared_ptr<Promise<std::shared_ptr<AnyMap>>>& /* result */)>>(std::move(func))) {}
282
+ inline void call(std::shared_ptr<Promise<std::shared_ptr<AnyMap>>> result) const noexcept {
283
+ _function->operator()(result);
284
+ }
285
+ private:
286
+ std::unique_ptr<std::function<void(const std::shared_ptr<Promise<std::shared_ptr<AnyMap>>>& /* result */)>> _function;
287
+ } SWIFT_NONCOPYABLE;
288
+ Func_void_std__shared_ptr_Promise_std__shared_ptr_AnyMap___ create_Func_void_std__shared_ptr_Promise_std__shared_ptr_AnyMap___(void* NON_NULL swiftClosureWrapper) noexcept;
289
+ inline Func_void_std__shared_ptr_Promise_std__shared_ptr_AnyMap____Wrapper wrap_Func_void_std__shared_ptr_Promise_std__shared_ptr_AnyMap___(Func_void_std__shared_ptr_Promise_std__shared_ptr_AnyMap___ value) noexcept {
290
+ return Func_void_std__shared_ptr_Promise_std__shared_ptr_AnyMap____Wrapper(std::move(value));
291
+ }
292
+
293
+ // pragma MARK: std::vector<ToolDefinition>
294
+ /**
295
+ * Specialized version of `std::vector<ToolDefinition>`.
296
+ */
297
+ using std__vector_ToolDefinition_ = std::vector<ToolDefinition>;
298
+ inline std::vector<ToolDefinition> create_std__vector_ToolDefinition_(size_t size) noexcept {
299
+ std::vector<ToolDefinition> vector;
300
+ vector.reserve(size);
301
+ return vector;
302
+ }
303
+
304
+ // pragma MARK: std::optional<std::vector<ToolDefinition>>
305
+ /**
306
+ * Specialized version of `std::optional<std::vector<ToolDefinition>>`.
307
+ */
308
+ using std__optional_std__vector_ToolDefinition__ = std::optional<std::vector<ToolDefinition>>;
309
+ inline std::optional<std::vector<ToolDefinition>> create_std__optional_std__vector_ToolDefinition__(const std::vector<ToolDefinition>& value) noexcept {
310
+ return std::optional<std::vector<ToolDefinition>>(value);
311
+ }
312
+ inline bool has_value_std__optional_std__vector_ToolDefinition__(const std::optional<std::vector<ToolDefinition>>& optional) noexcept {
313
+ return optional.has_value();
314
+ }
315
+ inline std::vector<ToolDefinition> get_std__optional_std__vector_ToolDefinition__(const std::optional<std::vector<ToolDefinition>>& optional) noexcept {
316
+ return *optional;
317
+ }
318
+
184
319
  // pragma MARK: std::optional<LLMLoadOptions>
185
320
  /**
186
321
  * Specialized version of `std::optional<LLMLoadOptions>`.
@@ -230,6 +365,43 @@ namespace margelo::nitro::mlxreactnative::bridge::swift {
230
365
  return Func_void_std__string_Wrapper(std::move(value));
231
366
  }
232
367
 
368
+ // pragma MARK: std::function<void(const std::string& /* toolName */, const std::string& /* args */)>
369
+ /**
370
+ * Specialized version of `std::function<void(const std::string&, const std::string&)>`.
371
+ */
372
+ using Func_void_std__string_std__string = std::function<void(const std::string& /* toolName */, const std::string& /* args */)>;
373
+ /**
374
+ * Wrapper class for a `std::function<void(const std::string& / * toolName * /, const std::string& / * args * /)>`, this can be used from Swift.
375
+ */
376
+ class Func_void_std__string_std__string_Wrapper final {
377
+ public:
378
+ explicit Func_void_std__string_std__string_Wrapper(std::function<void(const std::string& /* toolName */, const std::string& /* args */)>&& func): _function(std::make_unique<std::function<void(const std::string& /* toolName */, const std::string& /* args */)>>(std::move(func))) {}
379
+ inline void call(std::string toolName, std::string args) const noexcept {
380
+ _function->operator()(toolName, args);
381
+ }
382
+ private:
383
+ std::unique_ptr<std::function<void(const std::string& /* toolName */, const std::string& /* args */)>> _function;
384
+ } SWIFT_NONCOPYABLE;
385
+ Func_void_std__string_std__string create_Func_void_std__string_std__string(void* NON_NULL swiftClosureWrapper) noexcept;
386
+ inline Func_void_std__string_std__string_Wrapper wrap_Func_void_std__string_std__string(Func_void_std__string_std__string value) noexcept {
387
+ return Func_void_std__string_std__string_Wrapper(std::move(value));
388
+ }
389
+
390
+ // pragma MARK: std::optional<std::function<void(const std::string& /* toolName */, const std::string& /* args */)>>
391
+ /**
392
+ * Specialized version of `std::optional<std::function<void(const std::string& / * toolName * /, const std::string& / * args * /)>>`.
393
+ */
394
+ using std__optional_std__function_void_const_std__string_____toolName_____const_std__string_____args______ = std::optional<std::function<void(const std::string& /* toolName */, const std::string& /* args */)>>;
395
+ inline std::optional<std::function<void(const std::string& /* toolName */, const std::string& /* args */)>> create_std__optional_std__function_void_const_std__string_____toolName_____const_std__string_____args______(const std::function<void(const std::string& /* toolName */, const std::string& /* args */)>& value) noexcept {
396
+ return std::optional<std::function<void(const std::string& /* toolName */, const std::string& /* args */)>>(value);
397
+ }
398
+ inline bool has_value_std__optional_std__function_void_const_std__string_____toolName_____const_std__string_____args______(const std::optional<std::function<void(const std::string& /* toolName */, const std::string& /* args */)>>& optional) noexcept {
399
+ return optional.has_value();
400
+ }
401
+ inline std::function<void(const std::string& /* toolName */, const std::string& /* args */)> get_std__optional_std__function_void_const_std__string_____toolName_____const_std__string_____args______(const std::optional<std::function<void(const std::string& /* toolName */, const std::string& /* args */)>>& optional) noexcept {
402
+ return *optional;
403
+ }
404
+
233
405
  // pragma MARK: std::shared_ptr<HybridLLMSpec>
234
406
  /**
235
407
  * Specialized version of `std::shared_ptr<HybridLLMSpec>`.
@@ -2,7 +2,7 @@
2
2
  /// MLXReactNative-Swift-Cxx-Umbrella.hpp
3
3
  /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
4
  /// https://github.com/mrousavy/nitro
5
- /// Copyright © 2025 Marc Rousavy @ Margelo
5
+ /// Copyright © 2026 Marc Rousavy @ Margelo
6
6
  ///
7
7
 
8
8
  #pragma once
@@ -18,6 +18,10 @@ namespace margelo::nitro::mlxreactnative { class HybridModelManagerSpec; }
18
18
  namespace margelo::nitro::mlxreactnative { struct LLMLoadOptions; }
19
19
  // Forward declaration of `LLMMessage` to properly resolve imports.
20
20
  namespace margelo::nitro::mlxreactnative { struct LLMMessage; }
21
+ // Forward declaration of `ToolDefinition` to properly resolve imports.
22
+ namespace margelo::nitro::mlxreactnative { struct ToolDefinition; }
23
+ // Forward declaration of `ToolParameter` to properly resolve imports.
24
+ namespace margelo::nitro::mlxreactnative { struct ToolParameter; }
21
25
 
22
26
  // Include C++ defined types
23
27
  #include "GenerationStats.hpp"
@@ -25,6 +29,9 @@ namespace margelo::nitro::mlxreactnative { struct LLMMessage; }
25
29
  #include "HybridModelManagerSpec.hpp"
26
30
  #include "LLMLoadOptions.hpp"
27
31
  #include "LLMMessage.hpp"
32
+ #include "ToolDefinition.hpp"
33
+ #include "ToolParameter.hpp"
34
+ #include <NitroModules/AnyMap.hpp>
28
35
  #include <NitroModules/Promise.hpp>
29
36
  #include <NitroModules/Result.hpp>
30
37
  #include <exception>
@@ -2,7 +2,7 @@
2
2
  /// MLXReactNativeAutolinking.mm
3
3
  /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
4
  /// https://github.com/mrousavy/nitro
5
- /// Copyright © 2025 Marc Rousavy @ Margelo
5
+ /// Copyright © 2026 Marc Rousavy @ Margelo
6
6
  ///
7
7
 
8
8
  #import <Foundation/Foundation.h>
@@ -2,7 +2,7 @@
2
2
  /// MLXReactNativeAutolinking.swift
3
3
  /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
4
  /// https://github.com/mrousavy/nitro
5
- /// Copyright © 2025 Marc Rousavy @ Margelo
5
+ /// Copyright © 2026 Marc Rousavy @ Margelo
6
6
  ///
7
7
 
8
8
  public final class MLXReactNativeAutolinking {
@@ -2,7 +2,7 @@
2
2
  /// HybridLLMSpecSwift.cpp
3
3
  /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
4
  /// https://github.com/mrousavy/nitro
5
- /// Copyright © 2025 Marc Rousavy @ Margelo
5
+ /// Copyright © 2026 Marc Rousavy @ Margelo
6
6
  ///
7
7
 
8
8
  #include "HybridLLMSpecSwift.hpp"
@@ -2,7 +2,7 @@
2
2
  /// HybridLLMSpecSwift.hpp
3
3
  /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
4
  /// https://github.com/mrousavy/nitro
5
- /// Copyright © 2025 Marc Rousavy @ Margelo
5
+ /// Copyright © 2026 Marc Rousavy @ Margelo
6
6
  ///
7
7
 
8
8
  #pragma once
@@ -16,6 +16,10 @@ namespace MLXReactNative { class HybridLLMSpec_cxx; }
16
16
  namespace margelo::nitro::mlxreactnative { struct LLMLoadOptions; }
17
17
  // Forward declaration of `LLMMessage` to properly resolve imports.
18
18
  namespace margelo::nitro::mlxreactnative { struct LLMMessage; }
19
+ // Forward declaration of `ToolDefinition` to properly resolve imports.
20
+ namespace margelo::nitro::mlxreactnative { struct ToolDefinition; }
21
+ // Forward declaration of `ToolParameter` to properly resolve imports.
22
+ namespace margelo::nitro::mlxreactnative { struct ToolParameter; }
19
23
  // Forward declaration of `GenerationStats` to properly resolve imports.
20
24
  namespace margelo::nitro::mlxreactnative { struct GenerationStats; }
21
25
 
@@ -26,6 +30,9 @@ namespace margelo::nitro::mlxreactnative { struct GenerationStats; }
26
30
  #include <functional>
27
31
  #include "LLMMessage.hpp"
28
32
  #include <vector>
33
+ #include "ToolDefinition.hpp"
34
+ #include "ToolParameter.hpp"
35
+ #include <NitroModules/AnyMap.hpp>
29
36
  #include "GenerationStats.hpp"
30
37
 
31
38
  #include "MLXReactNative-Swift-Cxx-Umbrella.hpp"
@@ -110,8 +117,8 @@ namespace margelo::nitro::mlxreactnative {
110
117
  auto __value = std::move(__result.value());
111
118
  return __value;
112
119
  }
113
- inline std::shared_ptr<Promise<std::string>> stream(const std::string& prompt, const std::function<void(const std::string& /* token */)>& onToken) override {
114
- auto __result = _swiftPart.stream(prompt, onToken);
120
+ inline std::shared_ptr<Promise<std::string>> stream(const std::string& prompt, const std::function<void(const std::string& /* token */)>& onToken, const std::optional<std::function<void(const std::string& /* toolName */, const std::string& /* args */)>>& onToolCall) override {
121
+ auto __result = _swiftPart.stream(prompt, onToken, onToolCall);
115
122
  if (__result.hasError()) [[unlikely]] {
116
123
  std::rethrow_exception(__result.error());
117
124
  }
@@ -2,7 +2,7 @@
2
2
  /// HybridModelManagerSpecSwift.cpp
3
3
  /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
4
  /// https://github.com/mrousavy/nitro
5
- /// Copyright © 2025 Marc Rousavy @ Margelo
5
+ /// Copyright © 2026 Marc Rousavy @ Margelo
6
6
  ///
7
7
 
8
8
  #include "HybridModelManagerSpecSwift.hpp"
@@ -2,7 +2,7 @@
2
2
  /// HybridModelManagerSpecSwift.hpp
3
3
  /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
4
  /// https://github.com/mrousavy/nitro
5
- /// Copyright © 2025 Marc Rousavy @ Margelo
5
+ /// Copyright © 2026 Marc Rousavy @ Margelo
6
6
  ///
7
7
 
8
8
  #pragma once
@@ -0,0 +1,62 @@
1
+ ///
2
+ /// Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_AnyMap______std__shared_ptr_AnyMap_.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2026 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ import Foundation
9
+ import NitroModules
10
+
11
+ /**
12
+ * Wraps a Swift `(_ args: AnyMap) -> Promise<Promise<AnyMap>>` as a class.
13
+ * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
14
+ */
15
+ public final class Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_AnyMap______std__shared_ptr_AnyMap_ {
16
+ public typealias bridge = margelo.nitro.mlxreactnative.bridge.swift
17
+
18
+ private let closure: (_ args: AnyMap) -> Promise<Promise<AnyMap>>
19
+
20
+ public init(_ closure: @escaping (_ args: AnyMap) -> Promise<Promise<AnyMap>>) {
21
+ self.closure = closure
22
+ }
23
+
24
+ @inline(__always)
25
+ public func call(args: margelo.nitro.SharedAnyMap) -> bridge.std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_AnyMap_____ {
26
+ let __result: Promise<Promise<AnyMap>> = self.closure(AnyMap(withCppPart: args))
27
+ return { () -> bridge.std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_AnyMap_____ in
28
+ let __promise = bridge.create_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_AnyMap_____()
29
+ let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_AnyMap_____(__promise)
30
+ __result
31
+ .then({ __result in __promiseHolder.resolve({ () -> bridge.std__shared_ptr_Promise_std__shared_ptr_AnyMap___ in
32
+ let __promise = bridge.create_std__shared_ptr_Promise_std__shared_ptr_AnyMap___()
33
+ let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__shared_ptr_AnyMap___(__promise)
34
+ __result
35
+ .then({ __result in __promiseHolder.resolve(__result.cppPart) })
36
+ .catch({ __error in __promiseHolder.reject(__error.toCpp()) })
37
+ return __promise
38
+ }()) })
39
+ .catch({ __error in __promiseHolder.reject(__error.toCpp()) })
40
+ return __promise
41
+ }()
42
+ }
43
+
44
+ /**
45
+ * Casts this instance to a retained unsafe raw pointer.
46
+ * This acquires one additional strong reference on the object!
47
+ */
48
+ @inline(__always)
49
+ public func toUnsafe() -> UnsafeMutableRawPointer {
50
+ return Unmanaged.passRetained(self).toOpaque()
51
+ }
52
+
53
+ /**
54
+ * Casts an unsafe pointer to a `Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_AnyMap______std__shared_ptr_AnyMap_`.
55
+ * The pointer has to be a retained opaque `Unmanaged<Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_AnyMap______std__shared_ptr_AnyMap_>`.
56
+ * This removes one strong reference from the object!
57
+ */
58
+ @inline(__always)
59
+ public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_AnyMap______std__shared_ptr_AnyMap_ {
60
+ return Unmanaged<Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__shared_ptr_AnyMap______std__shared_ptr_AnyMap_>.fromOpaque(pointer).takeRetainedValue()
61
+ }
62
+ }
@@ -2,7 +2,7 @@
2
2
  /// Func_void.swift
3
3
  /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
4
  /// https://github.com/mrousavy/nitro
5
- /// Copyright © 2025 Marc Rousavy @ Margelo
5
+ /// Copyright © 2026 Marc Rousavy @ Margelo
6
6
  ///
7
7
 
8
8
  import Foundation
@@ -2,7 +2,7 @@
2
2
  /// Func_void_bool.swift
3
3
  /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
4
  /// https://github.com/mrousavy/nitro
5
- /// Copyright © 2025 Marc Rousavy @ Margelo
5
+ /// Copyright © 2026 Marc Rousavy @ Margelo
6
6
  ///
7
7
 
8
8
  import Foundation
@@ -2,7 +2,7 @@
2
2
  /// Func_void_double.swift
3
3
  /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
4
  /// https://github.com/mrousavy/nitro
5
- /// Copyright © 2025 Marc Rousavy @ Margelo
5
+ /// Copyright © 2026 Marc Rousavy @ Margelo
6
6
  ///
7
7
 
8
8
  import Foundation
@@ -2,7 +2,7 @@
2
2
  /// Func_void_std__exception_ptr.swift
3
3
  /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
4
  /// https://github.com/mrousavy/nitro
5
- /// Copyright © 2025 Marc Rousavy @ Margelo
5
+ /// Copyright © 2026 Marc Rousavy @ Margelo
6
6
  ///
7
7
 
8
8
  import Foundation
@@ -0,0 +1,47 @@
1
+ ///
2
+ /// Func_void_std__shared_ptr_AnyMap_.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2026 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ import Foundation
9
+ import NitroModules
10
+
11
+ /**
12
+ * Wraps a Swift `(_ value: AnyMap) -> Void` as a class.
13
+ * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
14
+ */
15
+ public final class Func_void_std__shared_ptr_AnyMap_ {
16
+ public typealias bridge = margelo.nitro.mlxreactnative.bridge.swift
17
+
18
+ private let closure: (_ value: AnyMap) -> Void
19
+
20
+ public init(_ closure: @escaping (_ value: AnyMap) -> Void) {
21
+ self.closure = closure
22
+ }
23
+
24
+ @inline(__always)
25
+ public func call(value: margelo.nitro.SharedAnyMap) -> Void {
26
+ self.closure(AnyMap(withCppPart: value))
27
+ }
28
+
29
+ /**
30
+ * Casts this instance to a retained unsafe raw pointer.
31
+ * This acquires one additional strong reference on the object!
32
+ */
33
+ @inline(__always)
34
+ public func toUnsafe() -> UnsafeMutableRawPointer {
35
+ return Unmanaged.passRetained(self).toOpaque()
36
+ }
37
+
38
+ /**
39
+ * Casts an unsafe pointer to a `Func_void_std__shared_ptr_AnyMap_`.
40
+ * The pointer has to be a retained opaque `Unmanaged<Func_void_std__shared_ptr_AnyMap_>`.
41
+ * This removes one strong reference from the object!
42
+ */
43
+ @inline(__always)
44
+ public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_std__shared_ptr_AnyMap_ {
45
+ return Unmanaged<Func_void_std__shared_ptr_AnyMap_>.fromOpaque(pointer).takeRetainedValue()
46
+ }
47
+ }
@@ -0,0 +1,67 @@
1
+ ///
2
+ /// Func_void_std__shared_ptr_Promise_std__shared_ptr_AnyMap___.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2026 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ import Foundation
9
+ import NitroModules
10
+
11
+ /**
12
+ * Wraps a Swift `(_ value: Promise<AnyMap>) -> Void` as a class.
13
+ * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
14
+ */
15
+ public final class Func_void_std__shared_ptr_Promise_std__shared_ptr_AnyMap___ {
16
+ public typealias bridge = margelo.nitro.mlxreactnative.bridge.swift
17
+
18
+ private let closure: (_ value: Promise<AnyMap>) -> Void
19
+
20
+ public init(_ closure: @escaping (_ value: Promise<AnyMap>) -> Void) {
21
+ self.closure = closure
22
+ }
23
+
24
+ @inline(__always)
25
+ public func call(value: bridge.std__shared_ptr_Promise_std__shared_ptr_AnyMap___) -> Void {
26
+ self.closure({ () -> Promise<AnyMap> in
27
+ let __promise = Promise<AnyMap>()
28
+ let __resolver = { (__result: AnyMap) in
29
+ __promise.resolve(withResult: __result)
30
+ }
31
+ let __rejecter = { (__error: Error) in
32
+ __promise.reject(withError: __error)
33
+ }
34
+ let __resolverCpp = { () -> bridge.Func_void_std__shared_ptr_AnyMap_ in
35
+ let __closureWrapper = Func_void_std__shared_ptr_AnyMap_(__resolver)
36
+ return bridge.create_Func_void_std__shared_ptr_AnyMap_(__closureWrapper.toUnsafe())
37
+ }()
38
+ let __rejecterCpp = { () -> bridge.Func_void_std__exception_ptr in
39
+ let __closureWrapper = Func_void_std__exception_ptr(__rejecter)
40
+ return bridge.create_Func_void_std__exception_ptr(__closureWrapper.toUnsafe())
41
+ }()
42
+ let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__shared_ptr_AnyMap___(value)
43
+ __promiseHolder.addOnResolvedListener(__resolverCpp)
44
+ __promiseHolder.addOnRejectedListener(__rejecterCpp)
45
+ return __promise
46
+ }())
47
+ }
48
+
49
+ /**
50
+ * Casts this instance to a retained unsafe raw pointer.
51
+ * This acquires one additional strong reference on the object!
52
+ */
53
+ @inline(__always)
54
+ public func toUnsafe() -> UnsafeMutableRawPointer {
55
+ return Unmanaged.passRetained(self).toOpaque()
56
+ }
57
+
58
+ /**
59
+ * Casts an unsafe pointer to a `Func_void_std__shared_ptr_Promise_std__shared_ptr_AnyMap___`.
60
+ * The pointer has to be a retained opaque `Unmanaged<Func_void_std__shared_ptr_Promise_std__shared_ptr_AnyMap___>`.
61
+ * This removes one strong reference from the object!
62
+ */
63
+ @inline(__always)
64
+ public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_std__shared_ptr_Promise_std__shared_ptr_AnyMap___ {
65
+ return Unmanaged<Func_void_std__shared_ptr_Promise_std__shared_ptr_AnyMap___>.fromOpaque(pointer).takeRetainedValue()
66
+ }
67
+ }
@@ -2,7 +2,7 @@
2
2
  /// Func_void_std__string.swift
3
3
  /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
4
  /// https://github.com/mrousavy/nitro
5
- /// Copyright © 2025 Marc Rousavy @ Margelo
5
+ /// Copyright © 2026 Marc Rousavy @ Margelo
6
6
  ///
7
7
 
8
8
  import Foundation