@dr33m/react-native-litert-lm 0.5.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/LICENSE +21 -0
- package/README.md +627 -0
- package/android/CMakeLists.txt +32 -0
- package/android/build.gradle +104 -0
- package/android/src/main/AndroidManifest.xml +19 -0
- package/android/src/main/java/com/margelo/nitro/dev/litert/litertlm/HybridLiteRTLM.kt +888 -0
- package/android/src/main/java/com/margelo/nitro/dev/litert/litertlm/HybridModelStore.kt +189 -0
- package/android/src/main/java/com/margelo/nitro/dev/litert/litertlm/LiteRTLMRegistry.kt +32 -0
- package/android/src/main/java/com/margelo/nitro/dev/litert/litertlm/MultimodalPartFactories.kt +15 -0
- package/android/src/main/java/com/margelo/nitro/dev/litert/litertlm/StreamingCallbackListener.kt +89 -0
- package/android/src/main/java/dev/litert/litertlm/LiteRTLMInitProvider.kt +57 -0
- package/android/src/main/java/dev/litert/litertlm/LiteRTLMPackage.kt +43 -0
- package/android/src/test/java/com/margelo/nitro/core/Promise.kt +46 -0
- package/android/src/test/java/com/margelo/nitro/dev/litert/litertlm/HybridLiteRTLMTest.kt +122 -0
- package/app.plugin.js +58 -0
- package/cpp/cpp-adapter.cpp +21 -0
- package/cpp/include/README.md +32 -0
- package/cpp/include/litert_lm_engine.h +516 -0
- package/cpp/include/stb_image.h +7988 -0
- package/ios/HybridLiteRTLM+Execute.swift +287 -0
- package/ios/HybridLiteRTLM+Streaming.swift +153 -0
- package/ios/HybridLiteRTLM.swift +541 -0
- package/ios/HybridModelStore.swift +206 -0
- package/ios/MultimodalPart+Factories.swift +22 -0
- package/ios/Tests/HybridLiteRTLMTests.swift +187 -0
- package/lib/__mocks__/react-native-nitro-modules.d.ts +81 -0
- package/lib/__mocks__/react-native-nitro-modules.js +98 -0
- package/lib/__tests__/hooks.test.d.ts +1 -0
- package/lib/__tests__/hooks.test.js +175 -0
- package/lib/__tests__/inferenceRouting.test.d.ts +1 -0
- package/lib/__tests__/inferenceRouting.test.js +28 -0
- package/lib/__tests__/memoryTracker.test.d.ts +1 -0
- package/lib/__tests__/memoryTracker.test.js +74 -0
- package/lib/__tests__/modelFactory.test.d.ts +1 -0
- package/lib/__tests__/modelFactory.test.js +107 -0
- package/lib/__tests__/modelPath.test.d.ts +1 -0
- package/lib/__tests__/modelPath.test.js +12 -0
- package/lib/__tests__/modelRegistry.test.d.ts +1 -0
- package/lib/__tests__/modelRegistry.test.js +61 -0
- package/lib/hooks.d.ts +46 -0
- package/lib/hooks.js +159 -0
- package/lib/index.d.ts +142 -0
- package/lib/index.js +184 -0
- package/lib/inferenceRouting.d.ts +18 -0
- package/lib/inferenceRouting.js +63 -0
- package/lib/memoryTracker.d.ts +128 -0
- package/lib/memoryTracker.js +155 -0
- package/lib/modelFactory.d.ts +24 -0
- package/lib/modelFactory.js +128 -0
- package/lib/modelPath.d.ts +8 -0
- package/lib/modelPath.js +18 -0
- package/lib/modelRegistry.d.ts +55 -0
- package/lib/modelRegistry.js +82 -0
- package/lib/specs/LiteRTLM.nitro.d.ts +380 -0
- package/lib/specs/LiteRTLM.nitro.js +2 -0
- package/nitrogen/generated/.gitattributes +1 -0
- package/nitrogen/generated/android/LiteRTLM+autolinking.cmake +83 -0
- package/nitrogen/generated/android/LiteRTLM+autolinking.gradle +27 -0
- package/nitrogen/generated/android/LiteRTLMOnLoad.cpp +74 -0
- package/nitrogen/generated/android/LiteRTLMOnLoad.hpp +34 -0
- package/nitrogen/generated/android/c++/JBackend.hpp +61 -0
- package/nitrogen/generated/android/c++/JExecuteResult.hpp +86 -0
- package/nitrogen/generated/android/c++/JFunc_void_double.hpp +75 -0
- package/nitrogen/generated/android/c++/JFunc_void_std__string_bool.hpp +76 -0
- package/nitrogen/generated/android/c++/JGenerationStats.hpp +77 -0
- package/nitrogen/generated/android/c++/JHybridLiteRTLMSpec.cpp +371 -0
- package/nitrogen/generated/android/c++/JHybridLiteRTLMSpec.hpp +83 -0
- package/nitrogen/generated/android/c++/JHybridModelStoreSpec.cpp +101 -0
- package/nitrogen/generated/android/c++/JHybridModelStoreSpec.hpp +67 -0
- package/nitrogen/generated/android/c++/JLLMConfig.hpp +125 -0
- package/nitrogen/generated/android/c++/JMemoryUsage.hpp +69 -0
- package/nitrogen/generated/android/c++/JMessage.hpp +63 -0
- package/nitrogen/generated/android/c++/JModelFile.hpp +69 -0
- package/nitrogen/generated/android/c++/JMultimodalPart.hpp +78 -0
- package/nitrogen/generated/android/c++/JPartType.hpp +61 -0
- package/nitrogen/generated/android/c++/JRole.hpp +61 -0
- package/nitrogen/generated/android/c++/JToolCall.hpp +61 -0
- package/nitrogen/generated/android/c++/JToolDefinition.hpp +65 -0
- package/nitrogen/generated/android/c++/JToolResponse.hpp +61 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/Backend.kt +24 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/ExecuteResult.kt +61 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/Func_void_double.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/Func_void_std__string_bool.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/GenerationStats.kt +76 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/HybridLiteRTLMSpec.kt +165 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/HybridModelStoreSpec.kt +76 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/LLMConfig.kt +106 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/LiteRTLMOnLoad.kt +35 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/MemoryUsage.kt +66 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/Message.kt +56 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/ModelFile.kt +66 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/MultimodalPart.kt +71 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/PartType.kt +24 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/Role.kt +24 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/ToolCall.kt +56 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/ToolDefinition.kt +61 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/ToolResponse.kt +56 -0
- package/nitrogen/generated/ios/LiteRTLM+autolinking.rb +62 -0
- package/nitrogen/generated/ios/LiteRTLM-Swift-Cxx-Bridge.cpp +98 -0
- package/nitrogen/generated/ios/LiteRTLM-Swift-Cxx-Bridge.hpp +585 -0
- package/nitrogen/generated/ios/LiteRTLM-Swift-Cxx-Umbrella.hpp +93 -0
- package/nitrogen/generated/ios/LiteRTLMAutolinking.mm +41 -0
- package/nitrogen/generated/ios/LiteRTLMAutolinking.swift +38 -0
- package/nitrogen/generated/ios/c++/HybridLiteRTLMSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridLiteRTLMSpecSwift.hpp +279 -0
- package/nitrogen/generated/ios/c++/HybridModelStoreSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridModelStoreSpecSwift.hpp +117 -0
- package/nitrogen/generated/ios/swift/Backend.swift +44 -0
- package/nitrogen/generated/ios/swift/ExecuteResult.swift +45 -0
- package/nitrogen/generated/ios/swift/Func_void.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_ExecuteResult.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_double.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__string.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__string_bool.swift +46 -0
- package/nitrogen/generated/ios/swift/GenerationStats.swift +54 -0
- package/nitrogen/generated/ios/swift/HybridLiteRTLMSpec.swift +75 -0
- package/nitrogen/generated/ios/swift/HybridLiteRTLMSpec_cxx.swift +516 -0
- package/nitrogen/generated/ios/swift/HybridModelStoreSpec.swift +59 -0
- package/nitrogen/generated/ios/swift/HybridModelStoreSpec_cxx.swift +203 -0
- package/nitrogen/generated/ios/swift/LLMConfig.swift +239 -0
- package/nitrogen/generated/ios/swift/MemoryUsage.swift +44 -0
- package/nitrogen/generated/ios/swift/Message.swift +34 -0
- package/nitrogen/generated/ios/swift/ModelFile.swift +44 -0
- package/nitrogen/generated/ios/swift/MultimodalPart.swift +101 -0
- package/nitrogen/generated/ios/swift/PartType.swift +44 -0
- package/nitrogen/generated/ios/swift/Role.swift +44 -0
- package/nitrogen/generated/ios/swift/ToolCall.swift +34 -0
- package/nitrogen/generated/ios/swift/ToolDefinition.swift +39 -0
- package/nitrogen/generated/ios/swift/ToolResponse.swift +34 -0
- package/nitrogen/generated/shared/c++/Backend.hpp +80 -0
- package/nitrogen/generated/shared/c++/ExecuteResult.hpp +94 -0
- package/nitrogen/generated/shared/c++/GenerationStats.hpp +103 -0
- package/nitrogen/generated/shared/c++/HybridLiteRTLMSpec.cpp +41 -0
- package/nitrogen/generated/shared/c++/HybridLiteRTLMSpec.hpp +109 -0
- package/nitrogen/generated/shared/c++/HybridModelStoreSpec.cpp +25 -0
- package/nitrogen/generated/shared/c++/HybridModelStoreSpec.hpp +71 -0
- package/nitrogen/generated/shared/c++/LLMConfig.hpp +134 -0
- package/nitrogen/generated/shared/c++/MemoryUsage.hpp +95 -0
- package/nitrogen/generated/shared/c++/Message.hpp +89 -0
- package/nitrogen/generated/shared/c++/ModelFile.hpp +95 -0
- package/nitrogen/generated/shared/c++/MultimodalPart.hpp +103 -0
- package/nitrogen/generated/shared/c++/PartType.hpp +80 -0
- package/nitrogen/generated/shared/c++/Role.hpp +80 -0
- package/nitrogen/generated/shared/c++/ToolCall.hpp +87 -0
- package/nitrogen/generated/shared/c++/ToolDefinition.hpp +91 -0
- package/nitrogen/generated/shared/c++/ToolResponse.hpp +87 -0
- package/package.json +115 -0
- package/react-native-litert-lm.podspec +62 -0
- package/react-native.config.js +16 -0
- package/scripts/download-ios-frameworks.sh +39 -0
- package/scripts/framework-source.js +46 -0
- package/scripts/postinstall.js +145 -0
- package/src/__mocks__/react-native-nitro-modules.ts +132 -0
- package/src/__tests__/hooks.test.ts +216 -0
- package/src/__tests__/inferenceRouting.test.ts +36 -0
- package/src/__tests__/memoryTracker.test.ts +87 -0
- package/src/__tests__/modelFactory.test.ts +153 -0
- package/src/__tests__/modelPath.test.ts +14 -0
- package/src/__tests__/modelRegistry.test.ts +73 -0
- package/src/hooks.ts +234 -0
- package/src/index.ts +214 -0
- package/src/inferenceRouting.ts +80 -0
- package/src/memoryTracker.ts +268 -0
- package/src/modelFactory.ts +163 -0
- package/src/modelPath.ts +16 -0
- package/src/modelRegistry.ts +104 -0
- package/src/specs/LiteRTLM.nitro.ts +451 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Role.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
|
+
#if __has_include(<NitroModules/NitroHash.hpp>)
|
|
11
|
+
#include <NitroModules/NitroHash.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
#if __has_include(<NitroModules/JSIConverter.hpp>)
|
|
16
|
+
#include <NitroModules/JSIConverter.hpp>
|
|
17
|
+
#else
|
|
18
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
19
|
+
#endif
|
|
20
|
+
#if __has_include(<NitroModules/NitroDefines.hpp>)
|
|
21
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
22
|
+
#else
|
|
23
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
24
|
+
#endif
|
|
25
|
+
|
|
26
|
+
namespace margelo::nitro::litertlm {
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* An enum which can be represented as a JavaScript union (Role).
|
|
30
|
+
*/
|
|
31
|
+
enum class Role {
|
|
32
|
+
USER SWIFT_NAME(user) = 0,
|
|
33
|
+
MODEL SWIFT_NAME(model) = 1,
|
|
34
|
+
SYSTEM SWIFT_NAME(system) = 2,
|
|
35
|
+
} CLOSED_ENUM;
|
|
36
|
+
|
|
37
|
+
} // namespace margelo::nitro::litertlm
|
|
38
|
+
|
|
39
|
+
namespace margelo::nitro {
|
|
40
|
+
|
|
41
|
+
// C++ Role <> JS Role (union)
|
|
42
|
+
template <>
|
|
43
|
+
struct JSIConverter<margelo::nitro::litertlm::Role> final {
|
|
44
|
+
static inline margelo::nitro::litertlm::Role fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
45
|
+
std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, arg);
|
|
46
|
+
switch (hashString(unionValue.c_str(), unionValue.size())) {
|
|
47
|
+
case hashString("user"): return margelo::nitro::litertlm::Role::USER;
|
|
48
|
+
case hashString("model"): return margelo::nitro::litertlm::Role::MODEL;
|
|
49
|
+
case hashString("system"): return margelo::nitro::litertlm::Role::SYSTEM;
|
|
50
|
+
default: [[unlikely]]
|
|
51
|
+
throw std::invalid_argument("Cannot convert \"" + unionValue + "\" to enum Role - invalid value!");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, margelo::nitro::litertlm::Role arg) {
|
|
55
|
+
switch (arg) {
|
|
56
|
+
case margelo::nitro::litertlm::Role::USER: return JSIConverter<std::string>::toJSI(runtime, "user");
|
|
57
|
+
case margelo::nitro::litertlm::Role::MODEL: return JSIConverter<std::string>::toJSI(runtime, "model");
|
|
58
|
+
case margelo::nitro::litertlm::Role::SYSTEM: return JSIConverter<std::string>::toJSI(runtime, "system");
|
|
59
|
+
default: [[unlikely]]
|
|
60
|
+
throw std::invalid_argument("Cannot convert Role to JS - invalid value: "
|
|
61
|
+
+ std::to_string(static_cast<int>(arg)) + "!");
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
65
|
+
if (!value.isString()) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, value);
|
|
69
|
+
switch (hashString(unionValue.c_str(), unionValue.size())) {
|
|
70
|
+
case hashString("user"):
|
|
71
|
+
case hashString("model"):
|
|
72
|
+
case hashString("system"):
|
|
73
|
+
return true;
|
|
74
|
+
default:
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// ToolCall.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
|
+
#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
|
+
#if __has_include(<NitroModules/PropNameIDCache.hpp>)
|
|
26
|
+
#include <NitroModules/PropNameIDCache.hpp>
|
|
27
|
+
#else
|
|
28
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
29
|
+
#endif
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
#include <string>
|
|
34
|
+
|
|
35
|
+
namespace margelo::nitro::litertlm {
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A struct which can be represented as a JavaScript object (ToolCall).
|
|
39
|
+
*/
|
|
40
|
+
struct ToolCall final {
|
|
41
|
+
public:
|
|
42
|
+
std::string name SWIFT_PRIVATE;
|
|
43
|
+
std::string argumentsJson SWIFT_PRIVATE;
|
|
44
|
+
|
|
45
|
+
public:
|
|
46
|
+
ToolCall() = default;
|
|
47
|
+
explicit ToolCall(std::string name, std::string argumentsJson): name(name), argumentsJson(argumentsJson) {}
|
|
48
|
+
|
|
49
|
+
public:
|
|
50
|
+
friend bool operator==(const ToolCall& lhs, const ToolCall& rhs) = default;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
} // namespace margelo::nitro::litertlm
|
|
54
|
+
|
|
55
|
+
namespace margelo::nitro {
|
|
56
|
+
|
|
57
|
+
// C++ ToolCall <> JS ToolCall (object)
|
|
58
|
+
template <>
|
|
59
|
+
struct JSIConverter<margelo::nitro::litertlm::ToolCall> final {
|
|
60
|
+
static inline margelo::nitro::litertlm::ToolCall fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
61
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
62
|
+
return margelo::nitro::litertlm::ToolCall(
|
|
63
|
+
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "name"))),
|
|
64
|
+
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "argumentsJson")))
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::litertlm::ToolCall& arg) {
|
|
68
|
+
jsi::Object obj(runtime);
|
|
69
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "name"), JSIConverter<std::string>::toJSI(runtime, arg.name));
|
|
70
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "argumentsJson"), JSIConverter<std::string>::toJSI(runtime, arg.argumentsJson));
|
|
71
|
+
return obj;
|
|
72
|
+
}
|
|
73
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
74
|
+
if (!value.isObject()) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
jsi::Object obj = value.getObject(runtime);
|
|
78
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "name")))) return false;
|
|
82
|
+
if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "argumentsJson")))) return false;
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// ToolDefinition.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
|
+
#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
|
+
#if __has_include(<NitroModules/PropNameIDCache.hpp>)
|
|
26
|
+
#include <NitroModules/PropNameIDCache.hpp>
|
|
27
|
+
#else
|
|
28
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
29
|
+
#endif
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
#include <string>
|
|
34
|
+
|
|
35
|
+
namespace margelo::nitro::litertlm {
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A struct which can be represented as a JavaScript object (ToolDefinition).
|
|
39
|
+
*/
|
|
40
|
+
struct ToolDefinition final {
|
|
41
|
+
public:
|
|
42
|
+
std::string name SWIFT_PRIVATE;
|
|
43
|
+
std::string description SWIFT_PRIVATE;
|
|
44
|
+
std::string parametersJson SWIFT_PRIVATE;
|
|
45
|
+
|
|
46
|
+
public:
|
|
47
|
+
ToolDefinition() = default;
|
|
48
|
+
explicit ToolDefinition(std::string name, std::string description, std::string parametersJson): name(name), description(description), parametersJson(parametersJson) {}
|
|
49
|
+
|
|
50
|
+
public:
|
|
51
|
+
friend bool operator==(const ToolDefinition& lhs, const ToolDefinition& rhs) = default;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
} // namespace margelo::nitro::litertlm
|
|
55
|
+
|
|
56
|
+
namespace margelo::nitro {
|
|
57
|
+
|
|
58
|
+
// C++ ToolDefinition <> JS ToolDefinition (object)
|
|
59
|
+
template <>
|
|
60
|
+
struct JSIConverter<margelo::nitro::litertlm::ToolDefinition> final {
|
|
61
|
+
static inline margelo::nitro::litertlm::ToolDefinition fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
62
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
63
|
+
return margelo::nitro::litertlm::ToolDefinition(
|
|
64
|
+
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "name"))),
|
|
65
|
+
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "description"))),
|
|
66
|
+
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "parametersJson")))
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::litertlm::ToolDefinition& arg) {
|
|
70
|
+
jsi::Object obj(runtime);
|
|
71
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "name"), JSIConverter<std::string>::toJSI(runtime, arg.name));
|
|
72
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "description"), JSIConverter<std::string>::toJSI(runtime, arg.description));
|
|
73
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "parametersJson"), JSIConverter<std::string>::toJSI(runtime, arg.parametersJson));
|
|
74
|
+
return obj;
|
|
75
|
+
}
|
|
76
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
77
|
+
if (!value.isObject()) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
jsi::Object obj = value.getObject(runtime);
|
|
81
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "name")))) return false;
|
|
85
|
+
if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "description")))) return false;
|
|
86
|
+
if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "parametersJson")))) return false;
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// ToolResponse.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
|
+
#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
|
+
#if __has_include(<NitroModules/PropNameIDCache.hpp>)
|
|
26
|
+
#include <NitroModules/PropNameIDCache.hpp>
|
|
27
|
+
#else
|
|
28
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
29
|
+
#endif
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
#include <string>
|
|
34
|
+
|
|
35
|
+
namespace margelo::nitro::litertlm {
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A struct which can be represented as a JavaScript object (ToolResponse).
|
|
39
|
+
*/
|
|
40
|
+
struct ToolResponse final {
|
|
41
|
+
public:
|
|
42
|
+
std::string name SWIFT_PRIVATE;
|
|
43
|
+
std::string responseJson SWIFT_PRIVATE;
|
|
44
|
+
|
|
45
|
+
public:
|
|
46
|
+
ToolResponse() = default;
|
|
47
|
+
explicit ToolResponse(std::string name, std::string responseJson): name(name), responseJson(responseJson) {}
|
|
48
|
+
|
|
49
|
+
public:
|
|
50
|
+
friend bool operator==(const ToolResponse& lhs, const ToolResponse& rhs) = default;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
} // namespace margelo::nitro::litertlm
|
|
54
|
+
|
|
55
|
+
namespace margelo::nitro {
|
|
56
|
+
|
|
57
|
+
// C++ ToolResponse <> JS ToolResponse (object)
|
|
58
|
+
template <>
|
|
59
|
+
struct JSIConverter<margelo::nitro::litertlm::ToolResponse> final {
|
|
60
|
+
static inline margelo::nitro::litertlm::ToolResponse fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
61
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
62
|
+
return margelo::nitro::litertlm::ToolResponse(
|
|
63
|
+
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "name"))),
|
|
64
|
+
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "responseJson")))
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::litertlm::ToolResponse& arg) {
|
|
68
|
+
jsi::Object obj(runtime);
|
|
69
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "name"), JSIConverter<std::string>::toJSI(runtime, arg.name));
|
|
70
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "responseJson"), JSIConverter<std::string>::toJSI(runtime, arg.responseJson));
|
|
71
|
+
return obj;
|
|
72
|
+
}
|
|
73
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
74
|
+
if (!value.isObject()) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
jsi::Object obj = value.getObject(runtime);
|
|
78
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "name")))) return false;
|
|
82
|
+
if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "responseJson")))) return false;
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
} // namespace margelo::nitro
|
package/package.json
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dr33m/react-native-litert-lm",
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"litertLm": {
|
|
5
|
+
"version": "0.12.0",
|
|
6
|
+
"androidMavenVersion": "0.12.0",
|
|
7
|
+
"iosGitTag": "v0.12.0"
|
|
8
|
+
},
|
|
9
|
+
"description": "High-performance LLM inference for React Native using LiteRT-LM. Optimized for Gemma 4 and other on-device language models.",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"author": "Thamsanqa Dreem (https://github.com/dr-33-m)",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/dr-33-m/react-native-litert-lm.git"
|
|
15
|
+
},
|
|
16
|
+
"homepage": "https://github.com/dr-33-m/react-native-litert-lm#readme",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/dr-33-m/react-native-litert-lm/issues"
|
|
19
|
+
},
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"react-native",
|
|
25
|
+
"nitro",
|
|
26
|
+
"litert",
|
|
27
|
+
"litert-lm",
|
|
28
|
+
"llm",
|
|
29
|
+
"gemma",
|
|
30
|
+
"gemma-4",
|
|
31
|
+
"gemma-3n",
|
|
32
|
+
"ai",
|
|
33
|
+
"machine-learning",
|
|
34
|
+
"on-device",
|
|
35
|
+
"inference",
|
|
36
|
+
"expo"
|
|
37
|
+
],
|
|
38
|
+
"main": "lib/index",
|
|
39
|
+
"module": "lib/index",
|
|
40
|
+
"types": "lib/index.d.ts",
|
|
41
|
+
"react-native": "src/index",
|
|
42
|
+
"source": "src/index",
|
|
43
|
+
"files": [
|
|
44
|
+
"src",
|
|
45
|
+
"lib",
|
|
46
|
+
"android/src",
|
|
47
|
+
"android/build.gradle",
|
|
48
|
+
"android/CMakeLists.txt",
|
|
49
|
+
"ios/**/*.swift",
|
|
50
|
+
"ios/**/*.mm",
|
|
51
|
+
"ios/**/*.m",
|
|
52
|
+
"cpp",
|
|
53
|
+
"nitrogen/generated",
|
|
54
|
+
"scripts/postinstall.js",
|
|
55
|
+
"scripts/framework-source.js",
|
|
56
|
+
"scripts/download-ios-frameworks.sh",
|
|
57
|
+
"react-native.config.js",
|
|
58
|
+
"react-native-litert-lm.podspec",
|
|
59
|
+
"app.plugin.js",
|
|
60
|
+
"README.md"
|
|
61
|
+
],
|
|
62
|
+
"sideEffects": false,
|
|
63
|
+
"engines": {
|
|
64
|
+
"node": ">=22"
|
|
65
|
+
},
|
|
66
|
+
"scripts": {
|
|
67
|
+
"postinstall": "node scripts/postinstall.js",
|
|
68
|
+
"build": "tsc",
|
|
69
|
+
"typecheck": "tsc --noEmit",
|
|
70
|
+
"test": "jest",
|
|
71
|
+
"lint": "eslint \"**/*.{js,ts,tsx}\" --fix",
|
|
72
|
+
"prepack": "npx nitrogen && npm run build",
|
|
73
|
+
"specs": "npx nitrogen",
|
|
74
|
+
"clean": "rm -rf lib android/build ios/build ios/Frameworks nitrogen/generated",
|
|
75
|
+
"download-frameworks": "scripts/download-ios-frameworks.sh",
|
|
76
|
+
"check-framework-release": "node scripts/check-framework-release.js",
|
|
77
|
+
"prepublishOnly": "node scripts/check-framework-release.js",
|
|
78
|
+
"android": "expo run:android",
|
|
79
|
+
"android:clean": "cd android && ./gradlew clean",
|
|
80
|
+
"ios": "expo run:ios",
|
|
81
|
+
"release": "release-it"
|
|
82
|
+
},
|
|
83
|
+
"devDependencies": {
|
|
84
|
+
"@expo/config-plugins": "~55.0.0",
|
|
85
|
+
"@types/jest": "^30.0.0",
|
|
86
|
+
"@types/react": "~19.2.10",
|
|
87
|
+
"@types/react-test-renderer": "^19.1.0",
|
|
88
|
+
"jest": "^30.4.2",
|
|
89
|
+
"react": "^19.2.6",
|
|
90
|
+
"react-native": "^0.85.3",
|
|
91
|
+
"react-native-nitro-modules": "^0.35.9",
|
|
92
|
+
"react-test-renderer": "^19.2.6",
|
|
93
|
+
"release-it": "^19.2.4",
|
|
94
|
+
"ts-jest": "^29.4.10",
|
|
95
|
+
"ts-node": "^10.9.2",
|
|
96
|
+
"typescript": "^5.0.0"
|
|
97
|
+
},
|
|
98
|
+
"peerDependencies": {
|
|
99
|
+
"expo": ">=55.0.0",
|
|
100
|
+
"react": "*",
|
|
101
|
+
"react-native": "*",
|
|
102
|
+
"react-native-nitro-modules": "^0.35.9"
|
|
103
|
+
},
|
|
104
|
+
"peerDependenciesMeta": {
|
|
105
|
+
"expo": {
|
|
106
|
+
"optional": true
|
|
107
|
+
},
|
|
108
|
+
"react": {
|
|
109
|
+
"optional": true
|
|
110
|
+
},
|
|
111
|
+
"react-native": {
|
|
112
|
+
"optional": true
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = "react-native-litert-lm"
|
|
7
|
+
s.version = package["version"]
|
|
8
|
+
s.summary = package["description"]
|
|
9
|
+
s.homepage = package["homepage"]
|
|
10
|
+
s.license = package["license"]
|
|
11
|
+
s.authors = package["author"]
|
|
12
|
+
s.platforms = { :ios => "15.1" }
|
|
13
|
+
s.module_name = "LiteRTLM"
|
|
14
|
+
s.source = { :git => package["repository"]["url"], :tag => "#{s.version}" }
|
|
15
|
+
|
|
16
|
+
s.swift_version = '5.9'
|
|
17
|
+
|
|
18
|
+
s.source_files = [
|
|
19
|
+
# Swift, Objective-C/C++ implementation & autolinking
|
|
20
|
+
"ios/*.{swift,m,mm}",
|
|
21
|
+
# Nitrogen generated iOS bridge & shared C++ interfaces
|
|
22
|
+
"nitrogen/generated/ios/**/*.{mm,swift}",
|
|
23
|
+
"nitrogen/generated/shared/c++/**/*.{hpp,cpp}",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
# Prebuilt LiteRT-LM C engine (xcframework). Not shipped in the npm tarball;
|
|
27
|
+
# fetched on install by scripts/postinstall.js (asset/tag defined in
|
|
28
|
+
# scripts/framework-source.js). Manual/upstream fallback:
|
|
29
|
+
# scripts/download-ios-frameworks.sh.
|
|
30
|
+
s.vendored_frameworks = 'ios/Frameworks/CLiteRTLM.xcframework'
|
|
31
|
+
|
|
32
|
+
s.pod_target_xcconfig = {
|
|
33
|
+
'CLANG_CXX_LANGUAGE_STANDARD' => 'c++20',
|
|
34
|
+
'SWIFT_VERSION' => '5.9',
|
|
35
|
+
'HEADER_SEARCH_PATHS' => [
|
|
36
|
+
'"$(PODS_TARGET_SRCROOT)/nitrogen/generated/shared/c++"',
|
|
37
|
+
'"$(PODS_TARGET_SRCROOT)/nitrogen/generated/ios"',
|
|
38
|
+
].join(' '),
|
|
39
|
+
'OTHER_LDFLAGS' => '$(inherited) -ObjC',
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
# Load nitrogen autolinking
|
|
43
|
+
load 'nitrogen/generated/ios/LiteRTLM+autolinking.rb'
|
|
44
|
+
add_nitrogen_files(s)
|
|
45
|
+
|
|
46
|
+
# Core React Native dependencies
|
|
47
|
+
s.dependency 'React-jsi'
|
|
48
|
+
s.dependency 'React-callinvoker'
|
|
49
|
+
s.dependency 'ReactCommon/turbomodule/core'
|
|
50
|
+
|
|
51
|
+
# Apple frameworks needed by LiteRT-LM engine
|
|
52
|
+
# Metal/MPS: GPU inference, Accelerate: BLAS/LAPACK, CoreML: delegate
|
|
53
|
+
s.frameworks = ['Metal', 'MetalPerformanceShaders', 'Accelerate', 'CoreML', 'CoreGraphics']
|
|
54
|
+
s.libraries = ['c++']
|
|
55
|
+
|
|
56
|
+
s.test_spec 'Tests' do |test_spec|
|
|
57
|
+
test_spec.source_files = 'ios/Tests/**/*.{swift}'
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
install_modules_dependencies(s)
|
|
61
|
+
end
|
|
62
|
+
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
dependency: {
|
|
3
|
+
platforms: {
|
|
4
|
+
android: {
|
|
5
|
+
sourceDir: "./android",
|
|
6
|
+
packageImportPath: "import dev.litert.litertlm.LiteRTLMPackage;",
|
|
7
|
+
packageInstance: "new LiteRTLMPackage()",
|
|
8
|
+
componentDescriptors: [],
|
|
9
|
+
cmakeListsPath: "CMakeLists.txt",
|
|
10
|
+
},
|
|
11
|
+
ios: {
|
|
12
|
+
podspecPath: "./react-native-litert-lm.podspec",
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# download-ios-frameworks.sh
|
|
3
|
+
# Downloads the official prebuilt LiteRT-LM iOS framework (CLiteRTLM.xcframework)
|
|
4
|
+
# directly from the google-ai-edge/LiteRT-LM releases.
|
|
5
|
+
|
|
6
|
+
set -euo pipefail
|
|
7
|
+
|
|
8
|
+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
9
|
+
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
|
10
|
+
|
|
11
|
+
# Resolve the asset URL + output dir from the shared single source of truth
|
|
12
|
+
# (scripts/framework-source.js) so this manual path can't drift from postinstall.
|
|
13
|
+
RELEASE_URL="$(node -e "console.log(require('$SCRIPT_DIR/framework-source').ASSET_URL)")"
|
|
14
|
+
OUTPUT_DIR="$(node -e "console.log(require('$SCRIPT_DIR/framework-source').FRAMEWORKS_DIR)")"
|
|
15
|
+
|
|
16
|
+
# Skip if already present
|
|
17
|
+
if [ -d "$OUTPUT_DIR/CLiteRTLM.xcframework" ]; then
|
|
18
|
+
echo "[LiteRT-LM] iOS CLiteRTLM.xcframework already present, skipping download."
|
|
19
|
+
exit 0
|
|
20
|
+
fi
|
|
21
|
+
|
|
22
|
+
echo "[LiteRT-LM] Downloading prebuilt iOS engine from Google's release:"
|
|
23
|
+
echo " ${RELEASE_URL}"
|
|
24
|
+
|
|
25
|
+
mkdir -p "$OUTPUT_DIR"
|
|
26
|
+
TMP_ZIP="$PROJECT_ROOT/.ios-frameworks-tmp.zip"
|
|
27
|
+
|
|
28
|
+
if curl -fsSL -o "$TMP_ZIP" "$RELEASE_URL"; then
|
|
29
|
+
echo "[LiteRT-LM] Download successful, extracting to $OUTPUT_DIR..."
|
|
30
|
+
rm -rf "$OUTPUT_DIR/CLiteRTLM.xcframework"
|
|
31
|
+
unzip -o -q "$TMP_ZIP" -d "$OUTPUT_DIR"
|
|
32
|
+
rm -f "$TMP_ZIP"
|
|
33
|
+
echo "[LiteRT-LM] ✅ iOS frameworks successfully installed."
|
|
34
|
+
exit 0
|
|
35
|
+
else
|
|
36
|
+
rm -f "$TMP_ZIP"
|
|
37
|
+
echo "Error: Failed to download LiteRT-LM iOS framework from ${RELEASE_URL}"
|
|
38
|
+
exit 1
|
|
39
|
+
fi
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* framework-source.js
|
|
3
|
+
*
|
|
4
|
+
* Single source of truth for the prebuilt iOS framework artifact, shared by
|
|
5
|
+
* scripts/postinstall.js, scripts/download-ios-frameworks.sh, and
|
|
6
|
+
* scripts/check-framework-release.js, so the asset name, tag, and URL can never
|
|
7
|
+
* drift between the install path and the release-time guardrail.
|
|
8
|
+
*
|
|
9
|
+
* The artifact is Google's canonical LiteRT-LM release (NOT a per-version
|
|
10
|
+
* re-host of this package), pinned to the LiteRT-LM **engine** version
|
|
11
|
+
* (`litertLm.iosGitTag` in package.json), NOT this wrapper's npm version. So:
|
|
12
|
+
* - patch releases of this wrapper reuse the same framework (no re-upload),
|
|
13
|
+
* - there is no per-release asset for the maintainer to forget to upload,
|
|
14
|
+
* - the guardrail checks the exact URL consumers fetch.
|
|
15
|
+
*
|
|
16
|
+
* Override the host/asset (e.g. to point at a private mirror) via env vars:
|
|
17
|
+
* LITERT_FRAMEWORK_REPO (default: google-ai-edge/LiteRT-LM)
|
|
18
|
+
* LITERT_FRAMEWORK_ASSET (default: CLiteRTLM.xcframework.zip)
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
const path = require('path');
|
|
22
|
+
const packageJson = require('../package.json');
|
|
23
|
+
|
|
24
|
+
/** GitHub repo that hosts the framework release asset. */
|
|
25
|
+
const GITHUB_REPO = process.env.LITERT_FRAMEWORK_REPO || 'google-ai-edge/LiteRT-LM';
|
|
26
|
+
|
|
27
|
+
/** Release asset filename. Must match the file on the GitHub release. */
|
|
28
|
+
const ASSET_NAME = process.env.LITERT_FRAMEWORK_ASSET || 'CLiteRTLM.xcframework.zip';
|
|
29
|
+
|
|
30
|
+
/** Release tag the asset lives under — the LiteRT-LM engine git tag, e.g. "v0.12.0". */
|
|
31
|
+
const FRAMEWORK_TAG = packageJson.litertLm.iosGitTag;
|
|
32
|
+
|
|
33
|
+
const PACKAGE_ROOT = path.resolve(__dirname, '..');
|
|
34
|
+
const FRAMEWORKS_DIR = path.join(PACKAGE_ROOT, 'ios', 'Frameworks');
|
|
35
|
+
|
|
36
|
+
/** Fully-resolved download URL for the framework zip. */
|
|
37
|
+
const ASSET_URL = `https://github.com/${GITHUB_REPO}/releases/download/${FRAMEWORK_TAG}/${ASSET_NAME}`;
|
|
38
|
+
|
|
39
|
+
module.exports = {
|
|
40
|
+
GITHUB_REPO,
|
|
41
|
+
ASSET_NAME,
|
|
42
|
+
FRAMEWORK_TAG,
|
|
43
|
+
PACKAGE_ROOT,
|
|
44
|
+
FRAMEWORKS_DIR,
|
|
45
|
+
ASSET_URL,
|
|
46
|
+
};
|