react-native-litert-lm 0.3.7 → 0.4.1

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 (88) hide show
  1. package/README.md +153 -135
  2. package/android/build.gradle +12 -0
  3. package/android/src/main/AndroidManifest.xml +8 -0
  4. package/android/src/main/java/com/margelo/nitro/dev/litert/litertlm/HybridLiteRTLM.kt +276 -62
  5. package/android/src/main/java/dev/litert/litertlm/LiteRTLMPackage.kt +19 -2
  6. package/android/src/test/java/com/margelo/nitro/core/Promise.kt +46 -0
  7. package/android/src/test/java/com/margelo/nitro/dev/litert/litertlm/HybridLiteRTLMTest.kt +105 -0
  8. package/ios/HybridLiteRTLM.swift +1344 -0
  9. package/ios/Tests/HybridLiteRTLMTests.swift +113 -0
  10. package/lib/__mocks__/react-native-nitro-modules.d.ts +65 -0
  11. package/lib/__mocks__/react-native-nitro-modules.js +60 -0
  12. package/lib/__tests__/hooks.test.d.ts +1 -0
  13. package/lib/__tests__/hooks.test.js +124 -0
  14. package/lib/__tests__/memoryTracker.test.d.ts +1 -0
  15. package/lib/__tests__/memoryTracker.test.js +74 -0
  16. package/lib/__tests__/modelFactory.test.d.ts +1 -0
  17. package/lib/__tests__/modelFactory.test.js +68 -0
  18. package/lib/hooks.js +27 -3
  19. package/lib/index.d.ts +6 -2
  20. package/lib/index.js +8 -8
  21. package/lib/modelFactory.js +82 -63
  22. package/lib/specs/LiteRTLM.nitro.d.ts +87 -2
  23. package/nitrogen/generated/android/LiteRTLMOnLoad.cpp +2 -2
  24. package/nitrogen/generated/android/c++/JHybridLiteRTLMSpec.cpp +94 -9
  25. package/nitrogen/generated/android/c++/JHybridLiteRTLMSpec.hpp +5 -1
  26. package/nitrogen/generated/android/c++/JLLMConfig.hpp +40 -3
  27. package/nitrogen/generated/android/c++/JMultimodalPart.hpp +74 -0
  28. package/nitrogen/generated/android/c++/JPartType.hpp +61 -0
  29. package/nitrogen/generated/android/c++/JToolDefinition.hpp +65 -0
  30. package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/GenerationStats.kt +23 -0
  31. package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/HybridLiteRTLMSpec.kt +28 -2
  32. package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/LLMConfig.kt +46 -3
  33. package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/MemoryUsage.kt +19 -0
  34. package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/Message.kt +15 -0
  35. package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/MultimodalPart.kt +66 -0
  36. package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/PartType.kt +24 -0
  37. package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/ToolDefinition.kt +61 -0
  38. package/nitrogen/generated/ios/LiteRTLM-Swift-Cxx-Bridge.cpp +57 -1
  39. package/nitrogen/generated/ios/LiteRTLM-Swift-Cxx-Bridge.hpp +414 -3
  40. package/nitrogen/generated/ios/LiteRTLM-Swift-Cxx-Umbrella.hpp +41 -3
  41. package/nitrogen/generated/ios/LiteRTLMAutolinking.mm +4 -6
  42. package/nitrogen/generated/ios/LiteRTLMAutolinking.swift +10 -0
  43. package/nitrogen/generated/ios/c++/HybridLiteRTLMSpecSwift.cpp +11 -0
  44. package/nitrogen/generated/ios/c++/HybridLiteRTLMSpecSwift.hpp +240 -0
  45. package/nitrogen/generated/ios/swift/Backend.swift +44 -0
  46. package/nitrogen/generated/ios/swift/Func_void.swift +46 -0
  47. package/nitrogen/generated/ios/swift/Func_void_double.swift +46 -0
  48. package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +46 -0
  49. package/nitrogen/generated/ios/swift/Func_void_std__string.swift +46 -0
  50. package/nitrogen/generated/ios/swift/Func_void_std__string_bool.swift +46 -0
  51. package/nitrogen/generated/ios/swift/GenerationStats.swift +54 -0
  52. package/nitrogen/generated/ios/swift/HybridLiteRTLMSpec.swift +71 -0
  53. package/nitrogen/generated/ios/swift/HybridLiteRTLMSpec_cxx.swift +431 -0
  54. package/nitrogen/generated/ios/swift/LLMConfig.swift +203 -0
  55. package/nitrogen/generated/ios/swift/MemoryUsage.swift +44 -0
  56. package/nitrogen/generated/ios/swift/Message.swift +34 -0
  57. package/nitrogen/generated/ios/swift/MultimodalPart.swift +83 -0
  58. package/nitrogen/generated/ios/swift/PartType.swift +44 -0
  59. package/nitrogen/generated/ios/swift/Role.swift +44 -0
  60. package/nitrogen/generated/ios/swift/ToolDefinition.swift +39 -0
  61. package/nitrogen/generated/shared/c++/HybridLiteRTLMSpec.cpp +4 -0
  62. package/nitrogen/generated/shared/c++/HybridLiteRTLMSpec.hpp +9 -2
  63. package/nitrogen/generated/shared/c++/LLMConfig.hpp +22 -2
  64. package/nitrogen/generated/shared/c++/MultimodalPart.hpp +99 -0
  65. package/nitrogen/generated/shared/c++/PartType.hpp +80 -0
  66. package/nitrogen/generated/shared/c++/ToolDefinition.hpp +91 -0
  67. package/package.json +22 -11
  68. package/react-native-litert-lm.podspec +17 -19
  69. package/scripts/download-ios-frameworks.sh +17 -50
  70. package/scripts/framework-source.js +46 -0
  71. package/scripts/postinstall.js +40 -18
  72. package/src/__mocks__/react-native-nitro-modules.ts +58 -0
  73. package/src/__tests__/hooks.test.ts +153 -0
  74. package/src/__tests__/memoryTracker.test.ts +87 -0
  75. package/src/__tests__/modelFactory.test.ts +96 -0
  76. package/src/hooks.ts +29 -7
  77. package/src/index.ts +7 -10
  78. package/src/modelFactory.ts +104 -80
  79. package/src/specs/LiteRTLM.nitro.ts +106 -2
  80. package/cpp/HybridLiteRTLM.cpp +0 -939
  81. package/cpp/HybridLiteRTLM.hpp +0 -169
  82. package/cpp/IOSDownloadHelper.h +0 -24
  83. package/ios/IOSDownloadHelper.mm +0 -129
  84. package/scripts/build-ios-engine.sh +0 -302
  85. package/scripts/stubs/cxx_bridge_stubs.cc +0 -224
  86. package/scripts/stubs/gemma_model_constraint_provider.cc +0 -46
  87. package/scripts/stubs/llguidance_stubs.c +0 -101
  88. package/src/templates.ts +0 -105
@@ -0,0 +1,61 @@
1
+ ///
2
+ /// JPartType.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #include <fbjni/fbjni.h>
11
+ #include "PartType.hpp"
12
+
13
+ namespace margelo::nitro::litertlm {
14
+
15
+ using namespace facebook;
16
+
17
+ /**
18
+ * The C++ JNI bridge between the C++ enum "PartType" and the the Kotlin enum "PartType".
19
+ */
20
+ struct JPartType final: public jni::JavaClass<JPartType> {
21
+ public:
22
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/dev/litert/litertlm/PartType;";
23
+
24
+ public:
25
+ /**
26
+ * Convert this Java/Kotlin-based enum to the C++ enum PartType.
27
+ */
28
+ [[maybe_unused]]
29
+ [[nodiscard]]
30
+ PartType toCpp() const {
31
+ static const auto clazz = javaClassStatic();
32
+ static const auto fieldOrdinal = clazz->getField<int>("value");
33
+ int ordinal = this->getFieldValue(fieldOrdinal);
34
+ return static_cast<PartType>(ordinal);
35
+ }
36
+
37
+ public:
38
+ /**
39
+ * Create a Java/Kotlin-based enum with the given C++ enum's value.
40
+ */
41
+ [[maybe_unused]]
42
+ static jni::alias_ref<JPartType> fromCpp(PartType value) {
43
+ static const auto clazz = javaClassStatic();
44
+ switch (value) {
45
+ case PartType::TEXT:
46
+ static const auto fieldTEXT = clazz->getStaticField<JPartType>("TEXT");
47
+ return clazz->getStaticFieldValue(fieldTEXT);
48
+ case PartType::IMAGE:
49
+ static const auto fieldIMAGE = clazz->getStaticField<JPartType>("IMAGE");
50
+ return clazz->getStaticFieldValue(fieldIMAGE);
51
+ case PartType::AUDIO:
52
+ static const auto fieldAUDIO = clazz->getStaticField<JPartType>("AUDIO");
53
+ return clazz->getStaticFieldValue(fieldAUDIO);
54
+ default:
55
+ std::string stringValue = std::to_string(static_cast<int>(value));
56
+ throw std::invalid_argument("Invalid enum value (" + stringValue + "!");
57
+ }
58
+ }
59
+ };
60
+
61
+ } // namespace margelo::nitro::litertlm
@@ -0,0 +1,65 @@
1
+ ///
2
+ /// JToolDefinition.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #include <fbjni/fbjni.h>
11
+ #include "ToolDefinition.hpp"
12
+
13
+ #include <string>
14
+
15
+ namespace margelo::nitro::litertlm {
16
+
17
+ using namespace facebook;
18
+
19
+ /**
20
+ * The C++ JNI bridge between the C++ struct "ToolDefinition" and the the Kotlin data class "ToolDefinition".
21
+ */
22
+ struct JToolDefinition final: public jni::JavaClass<JToolDefinition> {
23
+ public:
24
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/dev/litert/litertlm/ToolDefinition;";
25
+
26
+ public:
27
+ /**
28
+ * Convert this Java/Kotlin-based struct to the C++ struct ToolDefinition by copying all values to C++.
29
+ */
30
+ [[maybe_unused]]
31
+ [[nodiscard]]
32
+ ToolDefinition toCpp() const {
33
+ static const auto clazz = javaClassStatic();
34
+ static const auto fieldName = clazz->getField<jni::JString>("name");
35
+ jni::local_ref<jni::JString> name = this->getFieldValue(fieldName);
36
+ static const auto fieldDescription = clazz->getField<jni::JString>("description");
37
+ jni::local_ref<jni::JString> description = this->getFieldValue(fieldDescription);
38
+ static const auto fieldParametersJson = clazz->getField<jni::JString>("parametersJson");
39
+ jni::local_ref<jni::JString> parametersJson = this->getFieldValue(fieldParametersJson);
40
+ return ToolDefinition(
41
+ name->toStdString(),
42
+ description->toStdString(),
43
+ parametersJson->toStdString()
44
+ );
45
+ }
46
+
47
+ public:
48
+ /**
49
+ * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
50
+ */
51
+ [[maybe_unused]]
52
+ static jni::local_ref<JToolDefinition::javaobject> fromCpp(const ToolDefinition& value) {
53
+ using JSignature = JToolDefinition(jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>);
54
+ static const auto clazz = javaClassStatic();
55
+ static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
56
+ return create(
57
+ clazz,
58
+ jni::make_jstring(value.name),
59
+ jni::make_jstring(value.description),
60
+ jni::make_jstring(value.parametersJson)
61
+ );
62
+ }
63
+ };
64
+
65
+ } // namespace margelo::nitro::litertlm
@@ -9,6 +9,7 @@ package com.margelo.nitro.dev.litert.litertlm
9
9
 
10
10
  import androidx.annotation.Keep
11
11
  import com.facebook.proguard.annotations.DoNotStrip
12
+ import java.util.Objects
12
13
 
13
14
 
14
15
  /**
@@ -38,6 +39,28 @@ data class GenerationStats(
38
39
  ) {
39
40
  /* primary constructor */
40
41
 
42
+ override fun equals(other: Any?): Boolean {
43
+ if (this === other) return true
44
+ if (other !is GenerationStats) return false
45
+ return Objects.deepEquals(this.promptTokens, other.promptTokens)
46
+ && Objects.deepEquals(this.completionTokens, other.completionTokens)
47
+ && Objects.deepEquals(this.totalTokens, other.totalTokens)
48
+ && Objects.deepEquals(this.timeToFirstToken, other.timeToFirstToken)
49
+ && Objects.deepEquals(this.totalTime, other.totalTime)
50
+ && Objects.deepEquals(this.tokensPerSecond, other.tokensPerSecond)
51
+ }
52
+
53
+ override fun hashCode(): Int {
54
+ return arrayOf<Any?>(
55
+ promptTokens,
56
+ completionTokens,
57
+ totalTokens,
58
+ timeToFirstToken,
59
+ totalTime,
60
+ tokensPerSecond
61
+ ).contentDeepHashCode()
62
+ }
63
+
41
64
  companion object {
42
65
  /**
43
66
  * Constructor called from C++
@@ -41,6 +41,15 @@ abstract class HybridLiteRTLMSpec: HybridObject() {
41
41
  @Keep
42
42
  abstract fun sendMessageWithImage(message: String, imagePath: String): Promise<String>
43
43
 
44
+ abstract fun sendMessageWithImageAsync(message: String, imagePath: String, onToken: (token: String, done: Boolean) -> Unit): Promise<Unit>
45
+
46
+ @DoNotStrip
47
+ @Keep
48
+ private fun sendMessageWithImageAsync_cxx(message: String, imagePath: String, onToken: Func_void_std__string_bool): Promise<Unit> {
49
+ val __result = sendMessageWithImageAsync(message, imagePath, onToken)
50
+ return __result
51
+ }
52
+
44
53
  abstract fun downloadModel(url: String, fileName: String, onProgress: ((progress: Double) -> Unit)?): Promise<String>
45
54
 
46
55
  @DoNotStrip
@@ -58,11 +67,24 @@ abstract class HybridLiteRTLMSpec: HybridObject() {
58
67
  @Keep
59
68
  abstract fun sendMessageWithAudio(message: String, audioPath: String): Promise<String>
60
69
 
61
- abstract fun sendMessageAsync(message: String, onToken: (token: String, done: Boolean) -> Unit): Unit
70
+ abstract fun sendMessageWithAudioAsync(message: String, audioPath: String, onToken: (token: String, done: Boolean) -> Unit): Promise<Unit>
71
+
72
+ @DoNotStrip
73
+ @Keep
74
+ private fun sendMessageWithAudioAsync_cxx(message: String, audioPath: String, onToken: Func_void_std__string_bool): Promise<Unit> {
75
+ val __result = sendMessageWithAudioAsync(message, audioPath, onToken)
76
+ return __result
77
+ }
78
+
79
+ @DoNotStrip
80
+ @Keep
81
+ abstract fun sendMultimodalMessage(parts: Array<MultimodalPart>): Promise<String>
82
+
83
+ abstract fun sendMessageAsync(message: String, onToken: (token: String, done: Boolean) -> Unit): Promise<Unit>
62
84
 
63
85
  @DoNotStrip
64
86
  @Keep
65
- private fun sendMessageAsync_cxx(message: String, onToken: Func_void_std__string_bool): Unit {
87
+ private fun sendMessageAsync_cxx(message: String, onToken: Func_void_std__string_bool): Promise<Unit> {
66
88
  val __result = sendMessageAsync(message, onToken)
67
89
  return __result
68
90
  }
@@ -83,6 +105,10 @@ abstract class HybridLiteRTLMSpec: HybridObject() {
83
105
  @Keep
84
106
  abstract fun getStats(): GenerationStats
85
107
 
108
+ @DoNotStrip
109
+ @Keep
110
+ abstract fun countTokens(text: String): Double
111
+
86
112
  @DoNotStrip
87
113
  @Keep
88
114
  abstract fun getMemoryUsage(): MemoryUsage
@@ -9,6 +9,7 @@ package com.margelo.nitro.dev.litert.litertlm
9
9
 
10
10
  import androidx.annotation.Keep
11
11
  import com.facebook.proguard.annotations.DoNotStrip
12
+ import java.util.Objects
12
13
 
13
14
 
14
15
  /**
@@ -34,10 +35,52 @@ data class LLMConfig(
34
35
  val topK: Double?,
35
36
  @DoNotStrip
36
37
  @Keep
37
- val topP: Double?
38
+ val topP: Double?,
39
+ @DoNotStrip
40
+ @Keep
41
+ val validate: Boolean?,
42
+ @DoNotStrip
43
+ @Keep
44
+ val multimodal: Boolean?,
45
+ @DoNotStrip
46
+ @Keep
47
+ val tools: Array<ToolDefinition>?,
48
+ @DoNotStrip
49
+ @Keep
50
+ val enableSpeculativeDecoding: Boolean?
38
51
  ) {
39
52
  /* primary constructor */
40
53
 
54
+ override fun equals(other: Any?): Boolean {
55
+ if (this === other) return true
56
+ if (other !is LLMConfig) return false
57
+ return Objects.deepEquals(this.systemPrompt, other.systemPrompt)
58
+ && Objects.deepEquals(this.backend, other.backend)
59
+ && Objects.deepEquals(this.maxTokens, other.maxTokens)
60
+ && Objects.deepEquals(this.temperature, other.temperature)
61
+ && Objects.deepEquals(this.topK, other.topK)
62
+ && Objects.deepEquals(this.topP, other.topP)
63
+ && Objects.deepEquals(this.validate, other.validate)
64
+ && Objects.deepEquals(this.multimodal, other.multimodal)
65
+ && Objects.deepEquals(this.tools, other.tools)
66
+ && Objects.deepEquals(this.enableSpeculativeDecoding, other.enableSpeculativeDecoding)
67
+ }
68
+
69
+ override fun hashCode(): Int {
70
+ return arrayOf<Any?>(
71
+ systemPrompt,
72
+ backend,
73
+ maxTokens,
74
+ temperature,
75
+ topK,
76
+ topP,
77
+ validate,
78
+ multimodal,
79
+ tools,
80
+ enableSpeculativeDecoding
81
+ ).contentDeepHashCode()
82
+ }
83
+
41
84
  companion object {
42
85
  /**
43
86
  * Constructor called from C++
@@ -46,8 +89,8 @@ data class LLMConfig(
46
89
  @Keep
47
90
  @Suppress("unused")
48
91
  @JvmStatic
49
- private fun fromCpp(systemPrompt: String?, backend: Backend?, maxTokens: Double?, temperature: Double?, topK: Double?, topP: Double?): LLMConfig {
50
- return LLMConfig(systemPrompt, backend, maxTokens, temperature, topK, topP)
92
+ private fun fromCpp(systemPrompt: String?, backend: Backend?, maxTokens: Double?, temperature: Double?, topK: Double?, topP: Double?, validate: Boolean?, multimodal: Boolean?, tools: Array<ToolDefinition>?, enableSpeculativeDecoding: Boolean?): LLMConfig {
93
+ return LLMConfig(systemPrompt, backend, maxTokens, temperature, topK, topP, validate, multimodal, tools, enableSpeculativeDecoding)
51
94
  }
52
95
  }
53
96
  }
@@ -9,6 +9,7 @@ package com.margelo.nitro.dev.litert.litertlm
9
9
 
10
10
  import androidx.annotation.Keep
11
11
  import com.facebook.proguard.annotations.DoNotStrip
12
+ import java.util.Objects
12
13
 
13
14
 
14
15
  /**
@@ -32,6 +33,24 @@ data class MemoryUsage(
32
33
  ) {
33
34
  /* primary constructor */
34
35
 
36
+ override fun equals(other: Any?): Boolean {
37
+ if (this === other) return true
38
+ if (other !is MemoryUsage) return false
39
+ return Objects.deepEquals(this.nativeHeapBytes, other.nativeHeapBytes)
40
+ && Objects.deepEquals(this.residentBytes, other.residentBytes)
41
+ && Objects.deepEquals(this.availableMemoryBytes, other.availableMemoryBytes)
42
+ && Objects.deepEquals(this.isLowMemory, other.isLowMemory)
43
+ }
44
+
45
+ override fun hashCode(): Int {
46
+ return arrayOf<Any?>(
47
+ nativeHeapBytes,
48
+ residentBytes,
49
+ availableMemoryBytes,
50
+ isLowMemory
51
+ ).contentDeepHashCode()
52
+ }
53
+
35
54
  companion object {
36
55
  /**
37
56
  * Constructor called from C++
@@ -9,6 +9,7 @@ package com.margelo.nitro.dev.litert.litertlm
9
9
 
10
10
  import androidx.annotation.Keep
11
11
  import com.facebook.proguard.annotations.DoNotStrip
12
+ import java.util.Objects
12
13
 
13
14
 
14
15
  /**
@@ -26,6 +27,20 @@ data class Message(
26
27
  ) {
27
28
  /* primary constructor */
28
29
 
30
+ override fun equals(other: Any?): Boolean {
31
+ if (this === other) return true
32
+ if (other !is Message) return false
33
+ return Objects.deepEquals(this.role, other.role)
34
+ && Objects.deepEquals(this.content, other.content)
35
+ }
36
+
37
+ override fun hashCode(): Int {
38
+ return arrayOf<Any?>(
39
+ role,
40
+ content
41
+ ).contentDeepHashCode()
42
+ }
43
+
29
44
  companion object {
30
45
  /**
31
46
  * Constructor called from C++
@@ -0,0 +1,66 @@
1
+ ///
2
+ /// MultimodalPart.kt
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ package com.margelo.nitro.dev.litert.litertlm
9
+
10
+ import androidx.annotation.Keep
11
+ import com.facebook.proguard.annotations.DoNotStrip
12
+ import java.util.Objects
13
+ import com.margelo.nitro.core.ArrayBuffer
14
+
15
+ /**
16
+ * Represents the JavaScript object/struct "MultimodalPart".
17
+ */
18
+ @DoNotStrip
19
+ @Keep
20
+ data class MultimodalPart(
21
+ @DoNotStrip
22
+ @Keep
23
+ val type: PartType,
24
+ @DoNotStrip
25
+ @Keep
26
+ val text: String?,
27
+ @DoNotStrip
28
+ @Keep
29
+ val imageBuffer: ArrayBuffer?,
30
+ @DoNotStrip
31
+ @Keep
32
+ val audioBuffer: ArrayBuffer?
33
+ ) {
34
+ /* primary constructor */
35
+
36
+ override fun equals(other: Any?): Boolean {
37
+ if (this === other) return true
38
+ if (other !is MultimodalPart) return false
39
+ return Objects.deepEquals(this.type, other.type)
40
+ && Objects.deepEquals(this.text, other.text)
41
+ && Objects.deepEquals(this.imageBuffer, other.imageBuffer)
42
+ && Objects.deepEquals(this.audioBuffer, other.audioBuffer)
43
+ }
44
+
45
+ override fun hashCode(): Int {
46
+ return arrayOf<Any?>(
47
+ type,
48
+ text,
49
+ imageBuffer,
50
+ audioBuffer
51
+ ).contentDeepHashCode()
52
+ }
53
+
54
+ companion object {
55
+ /**
56
+ * Constructor called from C++
57
+ */
58
+ @DoNotStrip
59
+ @Keep
60
+ @Suppress("unused")
61
+ @JvmStatic
62
+ private fun fromCpp(type: PartType, text: String?, imageBuffer: ArrayBuffer?, audioBuffer: ArrayBuffer?): MultimodalPart {
63
+ return MultimodalPart(type, text, imageBuffer, audioBuffer)
64
+ }
65
+ }
66
+ }
@@ -0,0 +1,24 @@
1
+ ///
2
+ /// PartType.kt
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ package com.margelo.nitro.dev.litert.litertlm
9
+
10
+ import androidx.annotation.Keep
11
+ import com.facebook.proguard.annotations.DoNotStrip
12
+
13
+ /**
14
+ * Represents the JavaScript enum/union "PartType".
15
+ */
16
+ @DoNotStrip
17
+ @Keep
18
+ enum class PartType(@DoNotStrip @Keep val value: Int) {
19
+ TEXT(0),
20
+ IMAGE(1),
21
+ AUDIO(2);
22
+
23
+ companion object
24
+ }
@@ -0,0 +1,61 @@
1
+ ///
2
+ /// ToolDefinition.kt
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ package com.margelo.nitro.dev.litert.litertlm
9
+
10
+ import androidx.annotation.Keep
11
+ import com.facebook.proguard.annotations.DoNotStrip
12
+ import java.util.Objects
13
+
14
+
15
+ /**
16
+ * Represents the JavaScript object/struct "ToolDefinition".
17
+ */
18
+ @DoNotStrip
19
+ @Keep
20
+ data class ToolDefinition(
21
+ @DoNotStrip
22
+ @Keep
23
+ val name: String,
24
+ @DoNotStrip
25
+ @Keep
26
+ val description: String,
27
+ @DoNotStrip
28
+ @Keep
29
+ val parametersJson: String
30
+ ) {
31
+ /* primary constructor */
32
+
33
+ override fun equals(other: Any?): Boolean {
34
+ if (this === other) return true
35
+ if (other !is ToolDefinition) return false
36
+ return Objects.deepEquals(this.name, other.name)
37
+ && Objects.deepEquals(this.description, other.description)
38
+ && Objects.deepEquals(this.parametersJson, other.parametersJson)
39
+ }
40
+
41
+ override fun hashCode(): Int {
42
+ return arrayOf<Any?>(
43
+ name,
44
+ description,
45
+ parametersJson
46
+ ).contentDeepHashCode()
47
+ }
48
+
49
+ companion object {
50
+ /**
51
+ * Constructor called from C++
52
+ */
53
+ @DoNotStrip
54
+ @Keep
55
+ @Suppress("unused")
56
+ @JvmStatic
57
+ private fun fromCpp(name: String, description: String, parametersJson: String): ToolDefinition {
58
+ return ToolDefinition(name, description, parametersJson)
59
+ }
60
+ }
61
+ }
@@ -8,10 +8,66 @@
8
8
  #include "LiteRTLM-Swift-Cxx-Bridge.hpp"
9
9
 
10
10
  // Include C++ implementation defined types
11
-
11
+ #include "HybridLiteRTLMSpecSwift.hpp"
12
+ #include "LiteRTLM-Swift-Cxx-Umbrella.hpp"
13
+ #include <NitroModules/NitroDefines.hpp>
12
14
 
13
15
  namespace margelo::nitro::litertlm::bridge::swift {
14
16
 
17
+ // pragma MARK: std::function<void()>
18
+ Func_void create_Func_void(void* NON_NULL swiftClosureWrapper) noexcept {
19
+ auto swiftClosure = LiteRTLM::Func_void::fromUnsafe(swiftClosureWrapper);
20
+ return [swiftClosure = std::move(swiftClosure)]() mutable -> void {
21
+ swiftClosure.call();
22
+ };
23
+ }
24
+
25
+ // pragma MARK: std::function<void(const std::exception_ptr& /* error */)>
26
+ Func_void_std__exception_ptr create_Func_void_std__exception_ptr(void* NON_NULL swiftClosureWrapper) noexcept {
27
+ auto swiftClosure = LiteRTLM::Func_void_std__exception_ptr::fromUnsafe(swiftClosureWrapper);
28
+ return [swiftClosure = std::move(swiftClosure)](const std::exception_ptr& error) mutable -> void {
29
+ swiftClosure.call(error);
30
+ };
31
+ }
32
+
33
+ // pragma MARK: std::function<void(const std::string& /* result */)>
34
+ Func_void_std__string create_Func_void_std__string(void* NON_NULL swiftClosureWrapper) noexcept {
35
+ auto swiftClosure = LiteRTLM::Func_void_std__string::fromUnsafe(swiftClosureWrapper);
36
+ return [swiftClosure = std::move(swiftClosure)](const std::string& result) mutable -> void {
37
+ swiftClosure.call(result);
38
+ };
39
+ }
40
+
41
+ // pragma MARK: std::function<void(const std::string& /* token */, bool /* done */)>
42
+ Func_void_std__string_bool create_Func_void_std__string_bool(void* NON_NULL swiftClosureWrapper) noexcept {
43
+ auto swiftClosure = LiteRTLM::Func_void_std__string_bool::fromUnsafe(swiftClosureWrapper);
44
+ return [swiftClosure = std::move(swiftClosure)](const std::string& token, bool done) mutable -> void {
45
+ swiftClosure.call(token, done);
46
+ };
47
+ }
48
+
49
+ // pragma MARK: std::function<void(double /* progress */)>
50
+ Func_void_double create_Func_void_double(void* NON_NULL swiftClosureWrapper) noexcept {
51
+ auto swiftClosure = LiteRTLM::Func_void_double::fromUnsafe(swiftClosureWrapper);
52
+ return [swiftClosure = std::move(swiftClosure)](double progress) mutable -> void {
53
+ swiftClosure.call(progress);
54
+ };
55
+ }
15
56
 
57
+ // pragma MARK: std::shared_ptr<HybridLiteRTLMSpec>
58
+ std::shared_ptr<HybridLiteRTLMSpec> create_std__shared_ptr_HybridLiteRTLMSpec_(void* NON_NULL swiftUnsafePointer) noexcept {
59
+ LiteRTLM::HybridLiteRTLMSpec_cxx swiftPart = LiteRTLM::HybridLiteRTLMSpec_cxx::fromUnsafe(swiftUnsafePointer);
60
+ return std::make_shared<margelo::nitro::litertlm::HybridLiteRTLMSpecSwift>(swiftPart);
61
+ }
62
+ void* NON_NULL get_std__shared_ptr_HybridLiteRTLMSpec_(std__shared_ptr_HybridLiteRTLMSpec_ cppType) {
63
+ std::shared_ptr<margelo::nitro::litertlm::HybridLiteRTLMSpecSwift> swiftWrapper = std::dynamic_pointer_cast<margelo::nitro::litertlm::HybridLiteRTLMSpecSwift>(cppType);
64
+ #ifdef NITRO_DEBUG
65
+ if (swiftWrapper == nullptr) [[unlikely]] {
66
+ throw std::runtime_error("Class \"HybridLiteRTLMSpec\" is not implemented in Swift!");
67
+ }
68
+ #endif
69
+ LiteRTLM::HybridLiteRTLMSpec_cxx& swiftPart = swiftWrapper->getSwiftPart();
70
+ return swiftPart.toUnsafe();
71
+ }
16
72
 
17
73
  } // namespace margelo::nitro::litertlm::bridge::swift