react-native-nitro-mlx 0.2.2 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/MLXReactNative.podspec +7 -1
- package/ios/Sources/AudioCaptureManager.swift +110 -0
- package/ios/Sources/HybridLLM.swift +518 -42
- package/ios/Sources/HybridSTT.swift +202 -0
- package/ios/Sources/HybridTTS.swift +145 -0
- package/ios/Sources/JSONHelpers.swift +9 -0
- package/ios/Sources/ModelDownloader.swift +26 -12
- package/ios/Sources/StreamEventEmitter.swift +132 -0
- package/ios/Sources/ThinkingStateMachine.swift +206 -0
- package/lib/module/index.js +3 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/llm.js +72 -4
- package/lib/module/llm.js.map +1 -1
- package/lib/module/models.js +97 -26
- package/lib/module/models.js.map +1 -1
- package/lib/module/specs/STT.nitro.js +4 -0
- package/lib/module/specs/STT.nitro.js.map +1 -0
- package/lib/module/specs/TTS.nitro.js +4 -0
- package/lib/module/specs/TTS.nitro.js.map +1 -0
- package/lib/module/stt.js +49 -0
- package/lib/module/stt.js.map +1 -0
- package/lib/module/tool-utils.js +56 -0
- package/lib/module/tool-utils.js.map +1 -0
- package/lib/module/tts.js +40 -0
- package/lib/module/tts.js.map +1 -0
- package/lib/typescript/src/index.d.ts +8 -3
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/llm.d.ts +46 -4
- package/lib/typescript/src/llm.d.ts.map +1 -1
- package/lib/typescript/src/models.d.ts +13 -4
- package/lib/typescript/src/models.d.ts.map +1 -1
- package/lib/typescript/src/specs/LLM.nitro.d.ts +79 -7
- package/lib/typescript/src/specs/LLM.nitro.d.ts.map +1 -1
- package/lib/typescript/src/specs/STT.nitro.d.ts +28 -0
- package/lib/typescript/src/specs/STT.nitro.d.ts.map +1 -0
- package/lib/typescript/src/specs/TTS.nitro.d.ts +22 -0
- package/lib/typescript/src/specs/TTS.nitro.d.ts.map +1 -0
- package/lib/typescript/src/stt.d.ts +16 -0
- package/lib/typescript/src/stt.d.ts.map +1 -0
- package/lib/typescript/src/tool-utils.d.ts +13 -0
- package/lib/typescript/src/tool-utils.d.ts.map +1 -0
- package/lib/typescript/src/tts.d.ts +13 -0
- package/lib/typescript/src/tts.d.ts.map +1 -0
- package/nitrogen/generated/ios/MLXReactNative+autolinking.rb +1 -1
- package/nitrogen/generated/ios/MLXReactNative-Swift-Cxx-Bridge.cpp +76 -1
- package/nitrogen/generated/ios/MLXReactNative-Swift-Cxx-Bridge.hpp +338 -1
- package/nitrogen/generated/ios/MLXReactNative-Swift-Cxx-Umbrella.hpp +28 -1
- package/nitrogen/generated/ios/MLXReactNativeAutolinking.mm +17 -1
- package/nitrogen/generated/ios/MLXReactNativeAutolinking.swift +31 -1
- package/nitrogen/generated/ios/c++/HybridLLMSpecSwift.cpp +1 -1
- package/nitrogen/generated/ios/c++/HybridLLMSpecSwift.hpp +18 -3
- package/nitrogen/generated/ios/c++/HybridModelManagerSpecSwift.cpp +1 -1
- package/nitrogen/generated/ios/c++/HybridModelManagerSpecSwift.hpp +1 -1
- package/nitrogen/generated/ios/c++/HybridSTTSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridSTTSpecSwift.hpp +149 -0
- package/nitrogen/generated/ios/c++/HybridTTSSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridTTSSpecSwift.hpp +128 -0
- 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
- package/nitrogen/generated/ios/swift/Func_void.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_bool.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_double.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_std__shared_ptr_AnyMap_.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__shared_ptr_ArrayBuffer_.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__shared_ptr_Promise_std__shared_ptr_AnyMap___.swift +67 -0
- package/nitrogen/generated/ios/swift/Func_void_std__string.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_std__string_std__string.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__vector_std__string_.swift +1 -1
- package/nitrogen/generated/ios/swift/GenerationStats.swift +14 -3
- package/nitrogen/generated/ios/swift/HybridLLMSpec.swift +3 -2
- package/nitrogen/generated/ios/swift/HybridLLMSpec_cxx.swift +38 -2
- package/nitrogen/generated/ios/swift/HybridModelManagerSpec.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridModelManagerSpec_cxx.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridSTTSpec.swift +66 -0
- package/nitrogen/generated/ios/swift/HybridSTTSpec_cxx.swift +286 -0
- package/nitrogen/generated/ios/swift/HybridTTSSpec.swift +63 -0
- package/nitrogen/generated/ios/swift/HybridTTSSpec_cxx.swift +229 -0
- package/nitrogen/generated/ios/swift/LLMLoadOptions.swift +44 -2
- package/nitrogen/generated/ios/swift/LLMMessage.swift +1 -1
- package/nitrogen/generated/ios/swift/STTLoadOptions.swift +66 -0
- package/nitrogen/generated/ios/swift/TTSGenerateOptions.swift +78 -0
- package/nitrogen/generated/ios/swift/TTSLoadOptions.swift +66 -0
- package/nitrogen/generated/ios/swift/ToolDefinition.swift +113 -0
- package/nitrogen/generated/ios/swift/ToolParameter.swift +69 -0
- package/nitrogen/generated/shared/c++/GenerationStats.hpp +7 -3
- package/nitrogen/generated/shared/c++/HybridLLMSpec.cpp +2 -1
- package/nitrogen/generated/shared/c++/HybridLLMSpec.hpp +3 -2
- package/nitrogen/generated/shared/c++/HybridModelManagerSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridModelManagerSpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridSTTSpec.cpp +32 -0
- package/nitrogen/generated/shared/c++/HybridSTTSpec.hpp +78 -0
- package/nitrogen/generated/shared/c++/HybridTTSSpec.cpp +29 -0
- package/nitrogen/generated/shared/c++/HybridTTSSpec.hpp +78 -0
- package/nitrogen/generated/shared/c++/LLMLoadOptions.hpp +10 -3
- package/nitrogen/generated/shared/c++/LLMMessage.hpp +1 -1
- package/nitrogen/generated/shared/c++/STTLoadOptions.hpp +76 -0
- package/nitrogen/generated/shared/c++/TTSGenerateOptions.hpp +80 -0
- package/nitrogen/generated/shared/c++/TTSLoadOptions.hpp +76 -0
- package/nitrogen/generated/shared/c++/ToolDefinition.hpp +93 -0
- package/nitrogen/generated/shared/c++/ToolParameter.hpp +87 -0
- package/package.json +13 -8
- package/src/index.ts +40 -3
- package/src/llm.ts +90 -5
- package/src/models.ts +81 -1
- package/src/specs/LLM.nitro.ts +111 -7
- package/src/specs/STT.nitro.ts +35 -0
- package/src/specs/TTS.nitro.ts +30 -0
- package/src/stt.ts +67 -0
- package/src/tool-utils.ts +74 -0
- package/src/tts.ts +60 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// ToolParameter.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
|
+
* Represents an instance of `ToolParameter`, backed by a C++ struct.
|
|
13
|
+
*/
|
|
14
|
+
public typealias ToolParameter = margelo.nitro.mlxreactnative.ToolParameter
|
|
15
|
+
|
|
16
|
+
public extension ToolParameter {
|
|
17
|
+
private typealias bridge = margelo.nitro.mlxreactnative.bridge.swift
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Create a new instance of `ToolParameter`.
|
|
21
|
+
*/
|
|
22
|
+
init(name: String, type: String, description: String, required: Bool) {
|
|
23
|
+
self.init(std.string(name), std.string(type), std.string(description), required)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
var name: String {
|
|
27
|
+
@inline(__always)
|
|
28
|
+
get {
|
|
29
|
+
return String(self.__name)
|
|
30
|
+
}
|
|
31
|
+
@inline(__always)
|
|
32
|
+
set {
|
|
33
|
+
self.__name = std.string(newValue)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
var type: String {
|
|
38
|
+
@inline(__always)
|
|
39
|
+
get {
|
|
40
|
+
return String(self.__type)
|
|
41
|
+
}
|
|
42
|
+
@inline(__always)
|
|
43
|
+
set {
|
|
44
|
+
self.__type = std.string(newValue)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
var description: String {
|
|
49
|
+
@inline(__always)
|
|
50
|
+
get {
|
|
51
|
+
return String(self.__description)
|
|
52
|
+
}
|
|
53
|
+
@inline(__always)
|
|
54
|
+
set {
|
|
55
|
+
self.__description = std.string(newValue)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
var required: Bool {
|
|
60
|
+
@inline(__always)
|
|
61
|
+
get {
|
|
62
|
+
return self.__required
|
|
63
|
+
}
|
|
64
|
+
@inline(__always)
|
|
65
|
+
set {
|
|
66
|
+
self.__required = newValue
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// GenerationStats.hpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#pragma once
|
|
@@ -38,10 +38,11 @@ namespace margelo::nitro::mlxreactnative {
|
|
|
38
38
|
double tokensPerSecond SWIFT_PRIVATE;
|
|
39
39
|
double timeToFirstToken SWIFT_PRIVATE;
|
|
40
40
|
double totalTime SWIFT_PRIVATE;
|
|
41
|
+
double toolExecutionTime SWIFT_PRIVATE;
|
|
41
42
|
|
|
42
43
|
public:
|
|
43
44
|
GenerationStats() = default;
|
|
44
|
-
explicit GenerationStats(double tokenCount, double tokensPerSecond, double timeToFirstToken, double totalTime): tokenCount(tokenCount), tokensPerSecond(tokensPerSecond), timeToFirstToken(timeToFirstToken), totalTime(totalTime) {}
|
|
45
|
+
explicit GenerationStats(double tokenCount, double tokensPerSecond, double timeToFirstToken, double totalTime, double toolExecutionTime): tokenCount(tokenCount), tokensPerSecond(tokensPerSecond), timeToFirstToken(timeToFirstToken), totalTime(totalTime), toolExecutionTime(toolExecutionTime) {}
|
|
45
46
|
};
|
|
46
47
|
|
|
47
48
|
} // namespace margelo::nitro::mlxreactnative
|
|
@@ -57,7 +58,8 @@ namespace margelo::nitro {
|
|
|
57
58
|
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, "tokenCount")),
|
|
58
59
|
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, "tokensPerSecond")),
|
|
59
60
|
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, "timeToFirstToken")),
|
|
60
|
-
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, "totalTime"))
|
|
61
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, "totalTime")),
|
|
62
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, "toolExecutionTime"))
|
|
61
63
|
);
|
|
62
64
|
}
|
|
63
65
|
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::mlxreactnative::GenerationStats& arg) {
|
|
@@ -66,6 +68,7 @@ namespace margelo::nitro {
|
|
|
66
68
|
obj.setProperty(runtime, "tokensPerSecond", JSIConverter<double>::toJSI(runtime, arg.tokensPerSecond));
|
|
67
69
|
obj.setProperty(runtime, "timeToFirstToken", JSIConverter<double>::toJSI(runtime, arg.timeToFirstToken));
|
|
68
70
|
obj.setProperty(runtime, "totalTime", JSIConverter<double>::toJSI(runtime, arg.totalTime));
|
|
71
|
+
obj.setProperty(runtime, "toolExecutionTime", JSIConverter<double>::toJSI(runtime, arg.toolExecutionTime));
|
|
69
72
|
return obj;
|
|
70
73
|
}
|
|
71
74
|
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
@@ -80,6 +83,7 @@ namespace margelo::nitro {
|
|
|
80
83
|
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, "tokensPerSecond"))) return false;
|
|
81
84
|
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, "timeToFirstToken"))) return false;
|
|
82
85
|
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, "totalTime"))) return false;
|
|
86
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, "toolExecutionTime"))) return false;
|
|
83
87
|
return true;
|
|
84
88
|
}
|
|
85
89
|
};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// HybridLLMSpec.cpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#include "HybridLLMSpec.hpp"
|
|
@@ -24,6 +24,7 @@ namespace margelo::nitro::mlxreactnative {
|
|
|
24
24
|
prototype.registerHybridMethod("load", &HybridLLMSpec::load);
|
|
25
25
|
prototype.registerHybridMethod("generate", &HybridLLMSpec::generate);
|
|
26
26
|
prototype.registerHybridMethod("stream", &HybridLLMSpec::stream);
|
|
27
|
+
prototype.registerHybridMethod("streamWithEvents", &HybridLLMSpec::streamWithEvents);
|
|
27
28
|
prototype.registerHybridMethod("stop", &HybridLLMSpec::stop);
|
|
28
29
|
prototype.registerHybridMethod("unload", &HybridLLMSpec::unload);
|
|
29
30
|
prototype.registerHybridMethod("getLastGenerationStats", &HybridLLMSpec::getLastGenerationStats);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// HybridLLMSpec.hpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#pragma once
|
|
@@ -68,7 +68,8 @@ namespace margelo::nitro::mlxreactnative {
|
|
|
68
68
|
// Methods
|
|
69
69
|
virtual std::shared_ptr<Promise<void>> load(const std::string& modelId, const std::optional<LLMLoadOptions>& options) = 0;
|
|
70
70
|
virtual std::shared_ptr<Promise<std::string>> generate(const std::string& prompt) = 0;
|
|
71
|
-
virtual std::shared_ptr<Promise<std::string>> stream(const std::string& prompt, const std::function<void(const std::string& /* token */)>& onToken) = 0;
|
|
71
|
+
virtual 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) = 0;
|
|
72
|
+
virtual std::shared_ptr<Promise<std::string>> streamWithEvents(const std::string& prompt, const std::function<void(const std::string& /* eventJson */)>& onEvent) = 0;
|
|
72
73
|
virtual void stop() = 0;
|
|
73
74
|
virtual void unload() = 0;
|
|
74
75
|
virtual GenerationStats getLastGenerationStats() = 0;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// HybridModelManagerSpec.cpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#include "HybridModelManagerSpec.hpp"
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridSTTSpec.cpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#include "HybridSTTSpec.hpp"
|
|
9
|
+
|
|
10
|
+
namespace margelo::nitro::mlxreactnative {
|
|
11
|
+
|
|
12
|
+
void HybridSTTSpec::loadHybridMethods() {
|
|
13
|
+
// load base methods/properties
|
|
14
|
+
HybridObject::loadHybridMethods();
|
|
15
|
+
// load custom methods/properties
|
|
16
|
+
registerHybrids(this, [](Prototype& prototype) {
|
|
17
|
+
prototype.registerHybridGetter("isLoaded", &HybridSTTSpec::getIsLoaded);
|
|
18
|
+
prototype.registerHybridGetter("isTranscribing", &HybridSTTSpec::getIsTranscribing);
|
|
19
|
+
prototype.registerHybridGetter("isListening", &HybridSTTSpec::getIsListening);
|
|
20
|
+
prototype.registerHybridGetter("modelId", &HybridSTTSpec::getModelId);
|
|
21
|
+
prototype.registerHybridMethod("load", &HybridSTTSpec::load);
|
|
22
|
+
prototype.registerHybridMethod("transcribe", &HybridSTTSpec::transcribe);
|
|
23
|
+
prototype.registerHybridMethod("transcribeStream", &HybridSTTSpec::transcribeStream);
|
|
24
|
+
prototype.registerHybridMethod("startListening", &HybridSTTSpec::startListening);
|
|
25
|
+
prototype.registerHybridMethod("transcribeBuffer", &HybridSTTSpec::transcribeBuffer);
|
|
26
|
+
prototype.registerHybridMethod("stopListening", &HybridSTTSpec::stopListening);
|
|
27
|
+
prototype.registerHybridMethod("stop", &HybridSTTSpec::stop);
|
|
28
|
+
prototype.registerHybridMethod("unload", &HybridSTTSpec::unload);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
} // namespace margelo::nitro::mlxreactnative
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridSTTSpec.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#if __has_include(<NitroModules/HybridObject.hpp>)
|
|
11
|
+
#include <NitroModules/HybridObject.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
|
|
16
|
+
// Forward declaration of `STTLoadOptions` to properly resolve imports.
|
|
17
|
+
namespace margelo::nitro::mlxreactnative { struct STTLoadOptions; }
|
|
18
|
+
|
|
19
|
+
#include <string>
|
|
20
|
+
#include <NitroModules/Promise.hpp>
|
|
21
|
+
#include "STTLoadOptions.hpp"
|
|
22
|
+
#include <optional>
|
|
23
|
+
#include <NitroModules/ArrayBuffer.hpp>
|
|
24
|
+
#include <functional>
|
|
25
|
+
|
|
26
|
+
namespace margelo::nitro::mlxreactnative {
|
|
27
|
+
|
|
28
|
+
using namespace margelo::nitro;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* An abstract base class for `STT`
|
|
32
|
+
* Inherit this class to create instances of `HybridSTTSpec` in C++.
|
|
33
|
+
* You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
|
|
34
|
+
* @example
|
|
35
|
+
* ```cpp
|
|
36
|
+
* class HybridSTT: public HybridSTTSpec {
|
|
37
|
+
* public:
|
|
38
|
+
* HybridSTT(...): HybridObject(TAG) { ... }
|
|
39
|
+
* // ...
|
|
40
|
+
* };
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
class HybridSTTSpec: public virtual HybridObject {
|
|
44
|
+
public:
|
|
45
|
+
// Constructor
|
|
46
|
+
explicit HybridSTTSpec(): HybridObject(TAG) { }
|
|
47
|
+
|
|
48
|
+
// Destructor
|
|
49
|
+
~HybridSTTSpec() override = default;
|
|
50
|
+
|
|
51
|
+
public:
|
|
52
|
+
// Properties
|
|
53
|
+
virtual bool getIsLoaded() = 0;
|
|
54
|
+
virtual bool getIsTranscribing() = 0;
|
|
55
|
+
virtual bool getIsListening() = 0;
|
|
56
|
+
virtual std::string getModelId() = 0;
|
|
57
|
+
|
|
58
|
+
public:
|
|
59
|
+
// Methods
|
|
60
|
+
virtual std::shared_ptr<Promise<void>> load(const std::string& modelId, const std::optional<STTLoadOptions>& options) = 0;
|
|
61
|
+
virtual std::shared_ptr<Promise<std::string>> transcribe(const std::shared_ptr<ArrayBuffer>& audio) = 0;
|
|
62
|
+
virtual std::shared_ptr<Promise<std::string>> transcribeStream(const std::shared_ptr<ArrayBuffer>& audio, const std::function<void(const std::string& /* token */)>& onToken) = 0;
|
|
63
|
+
virtual std::shared_ptr<Promise<void>> startListening() = 0;
|
|
64
|
+
virtual std::shared_ptr<Promise<std::string>> transcribeBuffer() = 0;
|
|
65
|
+
virtual std::shared_ptr<Promise<std::string>> stopListening() = 0;
|
|
66
|
+
virtual void stop() = 0;
|
|
67
|
+
virtual void unload() = 0;
|
|
68
|
+
|
|
69
|
+
protected:
|
|
70
|
+
// Hybrid Setup
|
|
71
|
+
void loadHybridMethods() override;
|
|
72
|
+
|
|
73
|
+
protected:
|
|
74
|
+
// Tag for logging
|
|
75
|
+
static constexpr auto TAG = "STT";
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
} // namespace margelo::nitro::mlxreactnative
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridTTSSpec.cpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#include "HybridTTSSpec.hpp"
|
|
9
|
+
|
|
10
|
+
namespace margelo::nitro::mlxreactnative {
|
|
11
|
+
|
|
12
|
+
void HybridTTSSpec::loadHybridMethods() {
|
|
13
|
+
// load base methods/properties
|
|
14
|
+
HybridObject::loadHybridMethods();
|
|
15
|
+
// load custom methods/properties
|
|
16
|
+
registerHybrids(this, [](Prototype& prototype) {
|
|
17
|
+
prototype.registerHybridGetter("isLoaded", &HybridTTSSpec::getIsLoaded);
|
|
18
|
+
prototype.registerHybridGetter("isGenerating", &HybridTTSSpec::getIsGenerating);
|
|
19
|
+
prototype.registerHybridGetter("modelId", &HybridTTSSpec::getModelId);
|
|
20
|
+
prototype.registerHybridGetter("sampleRate", &HybridTTSSpec::getSampleRate);
|
|
21
|
+
prototype.registerHybridMethod("load", &HybridTTSSpec::load);
|
|
22
|
+
prototype.registerHybridMethod("generate", &HybridTTSSpec::generate);
|
|
23
|
+
prototype.registerHybridMethod("stream", &HybridTTSSpec::stream);
|
|
24
|
+
prototype.registerHybridMethod("stop", &HybridTTSSpec::stop);
|
|
25
|
+
prototype.registerHybridMethod("unload", &HybridTTSSpec::unload);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
} // namespace margelo::nitro::mlxreactnative
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridTTSSpec.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#if __has_include(<NitroModules/HybridObject.hpp>)
|
|
11
|
+
#include <NitroModules/HybridObject.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
|
|
16
|
+
// Forward declaration of `TTSLoadOptions` to properly resolve imports.
|
|
17
|
+
namespace margelo::nitro::mlxreactnative { struct TTSLoadOptions; }
|
|
18
|
+
// Forward declaration of `TTSGenerateOptions` to properly resolve imports.
|
|
19
|
+
namespace margelo::nitro::mlxreactnative { struct TTSGenerateOptions; }
|
|
20
|
+
|
|
21
|
+
#include <string>
|
|
22
|
+
#include <NitroModules/Promise.hpp>
|
|
23
|
+
#include "TTSLoadOptions.hpp"
|
|
24
|
+
#include <optional>
|
|
25
|
+
#include <NitroModules/ArrayBuffer.hpp>
|
|
26
|
+
#include "TTSGenerateOptions.hpp"
|
|
27
|
+
#include <functional>
|
|
28
|
+
|
|
29
|
+
namespace margelo::nitro::mlxreactnative {
|
|
30
|
+
|
|
31
|
+
using namespace margelo::nitro;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* An abstract base class for `TTS`
|
|
35
|
+
* Inherit this class to create instances of `HybridTTSSpec` in C++.
|
|
36
|
+
* You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
|
|
37
|
+
* @example
|
|
38
|
+
* ```cpp
|
|
39
|
+
* class HybridTTS: public HybridTTSSpec {
|
|
40
|
+
* public:
|
|
41
|
+
* HybridTTS(...): HybridObject(TAG) { ... }
|
|
42
|
+
* // ...
|
|
43
|
+
* };
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
class HybridTTSSpec: public virtual HybridObject {
|
|
47
|
+
public:
|
|
48
|
+
// Constructor
|
|
49
|
+
explicit HybridTTSSpec(): HybridObject(TAG) { }
|
|
50
|
+
|
|
51
|
+
// Destructor
|
|
52
|
+
~HybridTTSSpec() override = default;
|
|
53
|
+
|
|
54
|
+
public:
|
|
55
|
+
// Properties
|
|
56
|
+
virtual bool getIsLoaded() = 0;
|
|
57
|
+
virtual bool getIsGenerating() = 0;
|
|
58
|
+
virtual std::string getModelId() = 0;
|
|
59
|
+
virtual double getSampleRate() = 0;
|
|
60
|
+
|
|
61
|
+
public:
|
|
62
|
+
// Methods
|
|
63
|
+
virtual std::shared_ptr<Promise<void>> load(const std::string& modelId, const std::optional<TTSLoadOptions>& options) = 0;
|
|
64
|
+
virtual std::shared_ptr<Promise<std::shared_ptr<ArrayBuffer>>> generate(const std::string& text, const std::optional<TTSGenerateOptions>& options) = 0;
|
|
65
|
+
virtual std::shared_ptr<Promise<void>> stream(const std::string& text, const std::function<void(const std::shared_ptr<ArrayBuffer>& /* audio */)>& onAudioChunk, const std::optional<TTSGenerateOptions>& options) = 0;
|
|
66
|
+
virtual void stop() = 0;
|
|
67
|
+
virtual void unload() = 0;
|
|
68
|
+
|
|
69
|
+
protected:
|
|
70
|
+
// Hybrid Setup
|
|
71
|
+
void loadHybridMethods() override;
|
|
72
|
+
|
|
73
|
+
protected:
|
|
74
|
+
// Tag for logging
|
|
75
|
+
static constexpr auto TAG = "TTS";
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
} // namespace margelo::nitro::mlxreactnative
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// LLMLoadOptions.hpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#pragma once
|
|
@@ -25,11 +25,14 @@
|
|
|
25
25
|
|
|
26
26
|
// Forward declaration of `LLMMessage` to properly resolve imports.
|
|
27
27
|
namespace margelo::nitro::mlxreactnative { struct LLMMessage; }
|
|
28
|
+
// Forward declaration of `ToolDefinition` to properly resolve imports.
|
|
29
|
+
namespace margelo::nitro::mlxreactnative { struct ToolDefinition; }
|
|
28
30
|
|
|
29
31
|
#include <functional>
|
|
30
32
|
#include <optional>
|
|
31
33
|
#include "LLMMessage.hpp"
|
|
32
34
|
#include <vector>
|
|
35
|
+
#include "ToolDefinition.hpp"
|
|
33
36
|
|
|
34
37
|
namespace margelo::nitro::mlxreactnative {
|
|
35
38
|
|
|
@@ -41,10 +44,11 @@ namespace margelo::nitro::mlxreactnative {
|
|
|
41
44
|
std::optional<std::function<void(double /* progress */)>> onProgress SWIFT_PRIVATE;
|
|
42
45
|
std::optional<std::vector<LLMMessage>> additionalContext SWIFT_PRIVATE;
|
|
43
46
|
std::optional<bool> manageHistory SWIFT_PRIVATE;
|
|
47
|
+
std::optional<std::vector<ToolDefinition>> tools SWIFT_PRIVATE;
|
|
44
48
|
|
|
45
49
|
public:
|
|
46
50
|
LLMLoadOptions() = default;
|
|
47
|
-
explicit LLMLoadOptions(std::optional<std::function<void(double /* progress */)>> onProgress, std::optional<std::vector<LLMMessage>> additionalContext, std::optional<bool> manageHistory): onProgress(onProgress), additionalContext(additionalContext), manageHistory(manageHistory) {}
|
|
51
|
+
explicit LLMLoadOptions(std::optional<std::function<void(double /* progress */)>> onProgress, std::optional<std::vector<LLMMessage>> additionalContext, std::optional<bool> manageHistory, std::optional<std::vector<ToolDefinition>> tools): onProgress(onProgress), additionalContext(additionalContext), manageHistory(manageHistory), tools(tools) {}
|
|
48
52
|
};
|
|
49
53
|
|
|
50
54
|
} // namespace margelo::nitro::mlxreactnative
|
|
@@ -59,7 +63,8 @@ namespace margelo::nitro {
|
|
|
59
63
|
return margelo::nitro::mlxreactnative::LLMLoadOptions(
|
|
60
64
|
JSIConverter<std::optional<std::function<void(double)>>>::fromJSI(runtime, obj.getProperty(runtime, "onProgress")),
|
|
61
65
|
JSIConverter<std::optional<std::vector<margelo::nitro::mlxreactnative::LLMMessage>>>::fromJSI(runtime, obj.getProperty(runtime, "additionalContext")),
|
|
62
|
-
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, "manageHistory"))
|
|
66
|
+
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, "manageHistory")),
|
|
67
|
+
JSIConverter<std::optional<std::vector<margelo::nitro::mlxreactnative::ToolDefinition>>>::fromJSI(runtime, obj.getProperty(runtime, "tools"))
|
|
63
68
|
);
|
|
64
69
|
}
|
|
65
70
|
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::mlxreactnative::LLMLoadOptions& arg) {
|
|
@@ -67,6 +72,7 @@ namespace margelo::nitro {
|
|
|
67
72
|
obj.setProperty(runtime, "onProgress", JSIConverter<std::optional<std::function<void(double)>>>::toJSI(runtime, arg.onProgress));
|
|
68
73
|
obj.setProperty(runtime, "additionalContext", JSIConverter<std::optional<std::vector<margelo::nitro::mlxreactnative::LLMMessage>>>::toJSI(runtime, arg.additionalContext));
|
|
69
74
|
obj.setProperty(runtime, "manageHistory", JSIConverter<std::optional<bool>>::toJSI(runtime, arg.manageHistory));
|
|
75
|
+
obj.setProperty(runtime, "tools", JSIConverter<std::optional<std::vector<margelo::nitro::mlxreactnative::ToolDefinition>>>::toJSI(runtime, arg.tools));
|
|
70
76
|
return obj;
|
|
71
77
|
}
|
|
72
78
|
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
@@ -80,6 +86,7 @@ namespace margelo::nitro {
|
|
|
80
86
|
if (!JSIConverter<std::optional<std::function<void(double)>>>::canConvert(runtime, obj.getProperty(runtime, "onProgress"))) return false;
|
|
81
87
|
if (!JSIConverter<std::optional<std::vector<margelo::nitro::mlxreactnative::LLMMessage>>>::canConvert(runtime, obj.getProperty(runtime, "additionalContext"))) return false;
|
|
82
88
|
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, "manageHistory"))) return false;
|
|
89
|
+
if (!JSIConverter<std::optional<std::vector<margelo::nitro::mlxreactnative::ToolDefinition>>>::canConvert(runtime, obj.getProperty(runtime, "tools"))) return false;
|
|
83
90
|
return true;
|
|
84
91
|
}
|
|
85
92
|
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// STTLoadOptions.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#if __has_include(<NitroModules/JSIConverter.hpp>)
|
|
11
|
+
#include <NitroModules/JSIConverter.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
#if __has_include(<NitroModules/NitroDefines.hpp>)
|
|
16
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
17
|
+
#else
|
|
18
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
19
|
+
#endif
|
|
20
|
+
#if __has_include(<NitroModules/JSIHelpers.hpp>)
|
|
21
|
+
#include <NitroModules/JSIHelpers.hpp>
|
|
22
|
+
#else
|
|
23
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
24
|
+
#endif
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
#include <functional>
|
|
29
|
+
#include <optional>
|
|
30
|
+
|
|
31
|
+
namespace margelo::nitro::mlxreactnative {
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* A struct which can be represented as a JavaScript object (STTLoadOptions).
|
|
35
|
+
*/
|
|
36
|
+
struct STTLoadOptions {
|
|
37
|
+
public:
|
|
38
|
+
std::optional<std::function<void(double /* progress */)>> onProgress SWIFT_PRIVATE;
|
|
39
|
+
|
|
40
|
+
public:
|
|
41
|
+
STTLoadOptions() = default;
|
|
42
|
+
explicit STTLoadOptions(std::optional<std::function<void(double /* progress */)>> onProgress): onProgress(onProgress) {}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
} // namespace margelo::nitro::mlxreactnative
|
|
46
|
+
|
|
47
|
+
namespace margelo::nitro {
|
|
48
|
+
|
|
49
|
+
// C++ STTLoadOptions <> JS STTLoadOptions (object)
|
|
50
|
+
template <>
|
|
51
|
+
struct JSIConverter<margelo::nitro::mlxreactnative::STTLoadOptions> final {
|
|
52
|
+
static inline margelo::nitro::mlxreactnative::STTLoadOptions fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
53
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
54
|
+
return margelo::nitro::mlxreactnative::STTLoadOptions(
|
|
55
|
+
JSIConverter<std::optional<std::function<void(double)>>>::fromJSI(runtime, obj.getProperty(runtime, "onProgress"))
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::mlxreactnative::STTLoadOptions& arg) {
|
|
59
|
+
jsi::Object obj(runtime);
|
|
60
|
+
obj.setProperty(runtime, "onProgress", JSIConverter<std::optional<std::function<void(double)>>>::toJSI(runtime, arg.onProgress));
|
|
61
|
+
return obj;
|
|
62
|
+
}
|
|
63
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
64
|
+
if (!value.isObject()) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
jsi::Object obj = value.getObject(runtime);
|
|
68
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
if (!JSIConverter<std::optional<std::function<void(double)>>>::canConvert(runtime, obj.getProperty(runtime, "onProgress"))) return false;
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// TTSGenerateOptions.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#if __has_include(<NitroModules/JSIConverter.hpp>)
|
|
11
|
+
#include <NitroModules/JSIConverter.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
#if __has_include(<NitroModules/NitroDefines.hpp>)
|
|
16
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
17
|
+
#else
|
|
18
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
19
|
+
#endif
|
|
20
|
+
#if __has_include(<NitroModules/JSIHelpers.hpp>)
|
|
21
|
+
#include <NitroModules/JSIHelpers.hpp>
|
|
22
|
+
#else
|
|
23
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
24
|
+
#endif
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
#include <string>
|
|
29
|
+
#include <optional>
|
|
30
|
+
|
|
31
|
+
namespace margelo::nitro::mlxreactnative {
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* A struct which can be represented as a JavaScript object (TTSGenerateOptions).
|
|
35
|
+
*/
|
|
36
|
+
struct TTSGenerateOptions {
|
|
37
|
+
public:
|
|
38
|
+
std::optional<std::string> voice SWIFT_PRIVATE;
|
|
39
|
+
std::optional<double> speed SWIFT_PRIVATE;
|
|
40
|
+
|
|
41
|
+
public:
|
|
42
|
+
TTSGenerateOptions() = default;
|
|
43
|
+
explicit TTSGenerateOptions(std::optional<std::string> voice, std::optional<double> speed): voice(voice), speed(speed) {}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
} // namespace margelo::nitro::mlxreactnative
|
|
47
|
+
|
|
48
|
+
namespace margelo::nitro {
|
|
49
|
+
|
|
50
|
+
// C++ TTSGenerateOptions <> JS TTSGenerateOptions (object)
|
|
51
|
+
template <>
|
|
52
|
+
struct JSIConverter<margelo::nitro::mlxreactnative::TTSGenerateOptions> final {
|
|
53
|
+
static inline margelo::nitro::mlxreactnative::TTSGenerateOptions fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
54
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
55
|
+
return margelo::nitro::mlxreactnative::TTSGenerateOptions(
|
|
56
|
+
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "voice")),
|
|
57
|
+
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, "speed"))
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::mlxreactnative::TTSGenerateOptions& arg) {
|
|
61
|
+
jsi::Object obj(runtime);
|
|
62
|
+
obj.setProperty(runtime, "voice", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.voice));
|
|
63
|
+
obj.setProperty(runtime, "speed", JSIConverter<std::optional<double>>::toJSI(runtime, arg.speed));
|
|
64
|
+
return obj;
|
|
65
|
+
}
|
|
66
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
67
|
+
if (!value.isObject()) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
jsi::Object obj = value.getObject(runtime);
|
|
71
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "voice"))) return false;
|
|
75
|
+
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, "speed"))) return false;
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
} // namespace margelo::nitro
|