react-native-executorch 0.10.0 → 0.10.2
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/android/CMakeLists.txt +14 -0
- package/android/build.gradle.kts +44 -1
- package/legacy/cpp/rnexecutorch/RnExecutorchInstaller.cpp +23 -5
- package/legacy/cpp/rnexecutorch/host_objects/ModelHostObject.h +10 -3
- package/legacy/cpp/rnexecutorch/models/llm/LLM.cpp +11 -0
- package/legacy/cpp/rnexecutorch/threads/GlobalThreadPool.h +5 -1
- package/legacy/src/index.ts +5 -21
- package/lib/module/extensions/llm/tasks/llmChatSession.js +7 -2
- package/lib/module/extensions/llm/tasks/llmChatSession.js.map +1 -1
- package/lib/module/fetcher/telemetry.js +1 -1
- package/lib/module/legacy/src/index.js +5 -19
- package/lib/typescript/src/extensions/llm/tasks/llmChatSession.d.ts.map +1 -1
- package/package.json +2 -2
- package/react-native-executorch.podspec +186 -17
- package/scripts/download-libs.js +62 -23
- package/src/extensions/llm/tasks/llmChatSession.ts +7 -2
- package/src/fetcher/telemetry.ts +1 -1
package/android/CMakeLists.txt
CHANGED
|
@@ -55,6 +55,20 @@ file(GLOB_RECURSE LEGACY_CPP_SOURCES
|
|
|
55
55
|
${LEGACY_CPP_DIR}/runner/*.cpp
|
|
56
56
|
)
|
|
57
57
|
list(FILTER LEGACY_CPP_SOURCES EXCLUDE REGEX "/tests/")
|
|
58
|
+
# The legacy TTS models are the one part of the legacy tree that needs phonemis,
|
|
59
|
+
# so they follow the same toggle as the current phonemizer rather than being
|
|
60
|
+
# compiled unconditionally against a library that is not there.
|
|
61
|
+
if(NOT RNE_ENABLE_PHONEMIS)
|
|
62
|
+
list(FILTER LEGACY_CPP_SOURCES EXCLUDE REGEX "/models/text_to_speech/")
|
|
63
|
+
endif()
|
|
64
|
+
# Same story for opencv: the legacy vision models, the image/frame helpers they
|
|
65
|
+
# share and the multimodal LLM's vision encoder all compile against opencv2.
|
|
66
|
+
# Only the sources are dropped - the Types.h headers next to them are
|
|
67
|
+
# opencv-free and JsiConversions.h includes them unconditionally.
|
|
68
|
+
if(NOT RNE_ENABLE_OPENCV)
|
|
69
|
+
list(FILTER LEGACY_CPP_SOURCES EXCLUDE REGEX
|
|
70
|
+
"/data_processing/ImageProcessing\\.cpp$|/models/VisionModel\\.cpp$|/utils/Frame[^/]*\\.cpp$|/encoders/vision_encoder\\.cpp$|/models/(classification|embeddings/image|instance_segmentation|object_detection|ocr|pose_estimation|semantic_segmentation|style_transfer|text_to_image|vertical_ocr)/")
|
|
71
|
+
endif()
|
|
58
72
|
# ==============================================================================
|
|
59
73
|
|
|
60
74
|
set(PHONEMIS_SOURCES ${CPP_DIR}/extensions/speech/phonemizer.cpp)
|
package/android/build.gradle.kts
CHANGED
|
@@ -53,6 +53,44 @@ fun rneBuildConfig(): Map<*, *> {
|
|
|
53
53
|
val rneConfig = rneBuildConfig()
|
|
54
54
|
fun rneFlag(key: String): String = if (rneConfig[key] != false) "ON" else "OFF"
|
|
55
55
|
|
|
56
|
+
/**
|
|
57
|
+
* The prebuilt ExecuTorch runtime is not in the npm tarball - `package.json`
|
|
58
|
+
* excludes it and `scripts/download-libs.js` fetches it from the matching
|
|
59
|
+
* GitHub release in a postinstall hook. When a package manager skips that hook
|
|
60
|
+
* the install still looks clean and the failure surfaces much later, out of
|
|
61
|
+
* CMake, blamed on a missing library rather than on the install. Fail here with
|
|
62
|
+
* the fix instead.
|
|
63
|
+
*/
|
|
64
|
+
fun requireNativeArtifacts() {
|
|
65
|
+
val libsDir = file("../third-party/android/libs/executorch")
|
|
66
|
+
val present = libsDir.listFiles()
|
|
67
|
+
?.filter { it.isDirectory && it.resolve("libexecutorch.so").exists() }
|
|
68
|
+
.orEmpty()
|
|
69
|
+
if (present.isNotEmpty()) return
|
|
70
|
+
|
|
71
|
+
throw GradleException(
|
|
72
|
+
"""
|
|
73
|
+
react-native-executorch is missing its native artifacts:
|
|
74
|
+
|
|
75
|
+
${libsDir.absolutePath}
|
|
76
|
+
|
|
77
|
+
They are downloaded by this package's postinstall hook, which your
|
|
78
|
+
package manager did not run. pnpm 10 and later block dependency build
|
|
79
|
+
scripts by default ("Ignored build scripts"), and so do
|
|
80
|
+
`--ignore-scripts` and `npm ci --ignore-scripts`. Re-run the hook:
|
|
81
|
+
|
|
82
|
+
pnpm approve-builds react-native-executorch # pnpm
|
|
83
|
+
npm rebuild react-native-executorch # npm
|
|
84
|
+
node node_modules/react-native-executorch/scripts/download-libs.js
|
|
85
|
+
|
|
86
|
+
If you provision the libraries yourself, put them under
|
|
87
|
+
third-party/android/libs/executorch/<abi>/ before building.
|
|
88
|
+
""".trimIndent()
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
requireNativeArtifacts()
|
|
93
|
+
|
|
56
94
|
/**
|
|
57
95
|
* ExecuTorch only supports these ABIs. Honor the app's `reactNativeArchitectures`
|
|
58
96
|
* (e.g. Expo passes `-PreactNativeArchitectures=arm64-v8a` for device builds) so
|
|
@@ -70,7 +108,12 @@ android {
|
|
|
70
108
|
compileSdk = (getExtOrDefault("compileSdkVersion", 34) as Number).toInt()
|
|
71
109
|
|
|
72
110
|
defaultConfig {
|
|
73
|
-
|
|
111
|
+
// The prebuilt ExecuTorch runtime is compiled against Android API 26 -
|
|
112
|
+
// `.note.android.ident` in libexecutorch.so, libxnnpack_executorch_backend.so
|
|
113
|
+
// and libvulkan_executorch_backend.so all read 26 - so an app below that
|
|
114
|
+
// ships a library its linker is not guaranteed to be able to load. The
|
|
115
|
+
// default was 21, which let such a build through to fail on the device.
|
|
116
|
+
minSdk = (getExtOrDefault("minSdkVersion", 26) as Number).toInt()
|
|
74
117
|
targetSdk = (getExtOrDefault("targetSdkVersion", 34) as Number).toInt()
|
|
75
118
|
consumerProguardFiles("consumer-proguard-rules.pro")
|
|
76
119
|
|
|
@@ -2,21 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
#include <rnexecutorch/TokenizerModule.h>
|
|
4
4
|
#include <rnexecutorch/host_objects/JsiConversions.h>
|
|
5
|
+
#include <rnexecutorch/models/embeddings/text/TextEmbeddings.h>
|
|
6
|
+
#include <rnexecutorch/models/llm/LLM.h>
|
|
7
|
+
#ifdef RNE_ENABLE_OPENCV
|
|
5
8
|
#include <rnexecutorch/models/classification/Classification.h>
|
|
6
9
|
#include <rnexecutorch/models/embeddings/image/ImageEmbeddings.h>
|
|
7
|
-
#include <rnexecutorch/models/embeddings/text/TextEmbeddings.h>
|
|
8
10
|
#include <rnexecutorch/models/instance_segmentation/BaseInstanceSegmentation.h>
|
|
9
|
-
#include <rnexecutorch/models/llm/LLM.h>
|
|
10
11
|
#include <rnexecutorch/models/object_detection/ObjectDetection.h>
|
|
11
12
|
#include <rnexecutorch/models/ocr/OCR.h>
|
|
12
13
|
#include <rnexecutorch/models/pose_estimation/PoseEstimation.h>
|
|
13
|
-
#include <rnexecutorch/models/privacy_filter/PrivacyFilter.h>
|
|
14
14
|
#include <rnexecutorch/models/semantic_segmentation/BaseSemanticSegmentation.h>
|
|
15
|
-
#include <rnexecutorch/models/speech_to_text/SpeechToText.h>
|
|
16
15
|
#include <rnexecutorch/models/style_transfer/StyleTransfer.h>
|
|
17
16
|
#include <rnexecutorch/models/text_to_image/TextToImage.h>
|
|
18
|
-
#include <rnexecutorch/models/text_to_speech/TextToSpeech.h>
|
|
19
17
|
#include <rnexecutorch/models/vertical_ocr/VerticalOCR.h>
|
|
18
|
+
#endif
|
|
19
|
+
#include <rnexecutorch/models/privacy_filter/PrivacyFilter.h>
|
|
20
|
+
#include <rnexecutorch/models/speech_to_text/SpeechToText.h>
|
|
21
|
+
#ifdef RNE_ENABLE_PHONEMIS
|
|
22
|
+
#include <rnexecutorch/models/text_to_speech/TextToSpeech.h>
|
|
23
|
+
#endif
|
|
20
24
|
#include <rnexecutorch/models/voice_activity_detection/VoiceActivityDetection.h>
|
|
21
25
|
#include <rnexecutorch/threads/GlobalThreadPool.h>
|
|
22
26
|
#include <rnexecutorch/threads/utils/ThreadUtils.h>
|
|
@@ -42,6 +46,10 @@ void RnExecutorchInstaller::injectJSIBindings(
|
|
|
42
46
|
jsiRuntime->global().setProperty(*jsiRuntime, "__rne_isEmulator",
|
|
43
47
|
jsi::Value(isEmulator));
|
|
44
48
|
|
|
49
|
+
#ifdef RNE_ENABLE_OPENCV
|
|
50
|
+
// Registered only when opencv is compiled in. An app that opted out of it
|
|
51
|
+
// gets no `load*` global for these tasks, the same way the current API
|
|
52
|
+
// omits the whole `cv` namespace.
|
|
45
53
|
jsiRuntime->global().setProperty(
|
|
46
54
|
*jsiRuntime, "loadStyleTransfer",
|
|
47
55
|
RnExecutorchInstaller::loadModel<models::style_transfer::StyleTransfer>(
|
|
@@ -79,6 +87,7 @@ void RnExecutorchInstaller::injectJSIBindings(
|
|
|
79
87
|
*jsiRuntime, "loadPoseEstimation",
|
|
80
88
|
RnExecutorchInstaller::loadModel<models::pose_estimation::PoseEstimation>(
|
|
81
89
|
jsiRuntime, jsCallInvoker, "loadPoseEstimation"));
|
|
90
|
+
#endif
|
|
82
91
|
|
|
83
92
|
jsiRuntime->global().setProperty(
|
|
84
93
|
*jsiRuntime, "loadExecutorchModule",
|
|
@@ -90,10 +99,12 @@ void RnExecutorchInstaller::injectJSIBindings(
|
|
|
90
99
|
RnExecutorchInstaller::loadModel<TokenizerModule>(
|
|
91
100
|
jsiRuntime, jsCallInvoker, "loadTokenizerModule"));
|
|
92
101
|
|
|
102
|
+
#ifdef RNE_ENABLE_OPENCV
|
|
93
103
|
jsiRuntime->global().setProperty(
|
|
94
104
|
*jsiRuntime, "loadImageEmbeddings",
|
|
95
105
|
RnExecutorchInstaller::loadModel<models::embeddings::ImageEmbeddings>(
|
|
96
106
|
jsiRuntime, jsCallInvoker, "loadImageEmbeddings"));
|
|
107
|
+
#endif
|
|
97
108
|
|
|
98
109
|
jsiRuntime->global().setProperty(
|
|
99
110
|
*jsiRuntime, "loadTextEmbeddings",
|
|
@@ -110,6 +121,7 @@ void RnExecutorchInstaller::injectJSIBindings(
|
|
|
110
121
|
RnExecutorchInstaller::loadModel<models::privacy_filter::PrivacyFilter>(
|
|
111
122
|
jsiRuntime, jsCallInvoker, "loadPrivacyFilter"));
|
|
112
123
|
|
|
124
|
+
#ifdef RNE_ENABLE_OPENCV
|
|
113
125
|
jsiRuntime->global().setProperty(
|
|
114
126
|
*jsiRuntime, "loadOCR",
|
|
115
127
|
RnExecutorchInstaller::loadModel<models::ocr::OCR>(
|
|
@@ -119,16 +131,22 @@ void RnExecutorchInstaller::injectJSIBindings(
|
|
|
119
131
|
*jsiRuntime, "loadVerticalOCR",
|
|
120
132
|
RnExecutorchInstaller::loadModel<models::ocr::VerticalOCR>(
|
|
121
133
|
jsiRuntime, jsCallInvoker, "loadVerticalOCR"));
|
|
134
|
+
#endif
|
|
122
135
|
|
|
123
136
|
jsiRuntime->global().setProperty(
|
|
124
137
|
*jsiRuntime, "loadSpeechToText",
|
|
125
138
|
RnExecutorchInstaller::loadModel<models::speech_to_text::SpeechToText>(
|
|
126
139
|
jsiRuntime, jsCallInvoker, "loadSpeechToText"));
|
|
127
140
|
|
|
141
|
+
#ifdef RNE_ENABLE_PHONEMIS
|
|
142
|
+
// Only registered when phonemis is compiled in; an app that opted out of
|
|
143
|
+
// text-to-speech gets no `loadTextToSpeechKokoro` global, the same way the
|
|
144
|
+
// current API omits `speech.createPhonemizer`.
|
|
128
145
|
jsiRuntime->global().setProperty(
|
|
129
146
|
*jsiRuntime, "loadTextToSpeechKokoro",
|
|
130
147
|
RnExecutorchInstaller::loadModel<models::text_to_speech::kokoro::Kokoro>(
|
|
131
148
|
jsiRuntime, jsCallInvoker, "loadTextToSpeechKokoro"));
|
|
149
|
+
#endif
|
|
132
150
|
|
|
133
151
|
jsiRuntime->global().setProperty(
|
|
134
152
|
*jsiRuntime, "loadVAD",
|
|
@@ -17,13 +17,16 @@
|
|
|
17
17
|
#include <rnexecutorch/metaprogramming/FunctionHelpers.h>
|
|
18
18
|
#include <rnexecutorch/metaprogramming/TypeConcepts.h>
|
|
19
19
|
#include <rnexecutorch/models/BaseModel.h>
|
|
20
|
-
#include <rnexecutorch/models/VisionModel.h>
|
|
21
20
|
#include <rnexecutorch/models/llm/LLM.h>
|
|
21
|
+
#ifdef RNE_ENABLE_OPENCV
|
|
22
22
|
#include <rnexecutorch/models/ocr/OCR.h>
|
|
23
|
-
#include <rnexecutorch/models/speech_to_text/SpeechToText.h>
|
|
24
23
|
#include <rnexecutorch/models/text_to_image/TextToImage.h>
|
|
25
|
-
#include <rnexecutorch/models/text_to_speech/TextToSpeech.h>
|
|
26
24
|
#include <rnexecutorch/models/vertical_ocr/VerticalOCR.h>
|
|
25
|
+
#endif
|
|
26
|
+
#include <rnexecutorch/models/speech_to_text/SpeechToText.h>
|
|
27
|
+
#ifdef RNE_ENABLE_PHONEMIS
|
|
28
|
+
#include <rnexecutorch/models/text_to_speech/TextToSpeech.h>
|
|
29
|
+
#endif
|
|
27
30
|
#include <rnexecutorch/models/voice_activity_detection/VoiceActivityDetection.h>
|
|
28
31
|
#include <rnexecutorch/threads/GlobalThreadPool.h>
|
|
29
32
|
|
|
@@ -202,6 +205,7 @@ public:
|
|
|
202
205
|
"getVisualTokenCount"));
|
|
203
206
|
}
|
|
204
207
|
|
|
208
|
+
#ifdef RNE_ENABLE_OPENCV
|
|
205
209
|
if constexpr (meta::SameAs<Model, models::text_to_image::TextToImage>) {
|
|
206
210
|
addFunctions(
|
|
207
211
|
JSI_EXPORT_FUNCTION(ModelHostObject<Model>, unload, "unload"));
|
|
@@ -219,7 +223,9 @@ public:
|
|
|
219
223
|
addFunctions(
|
|
220
224
|
JSI_EXPORT_FUNCTION(ModelHostObject<Model>, unload, "unload"));
|
|
221
225
|
}
|
|
226
|
+
#endif
|
|
222
227
|
|
|
228
|
+
#ifdef RNE_ENABLE_PHONEMIS
|
|
223
229
|
if constexpr (meta::SameAs<Model, models::text_to_speech::kokoro::Kokoro>) {
|
|
224
230
|
addFunctions(
|
|
225
231
|
JSI_EXPORT_FUNCTION(ModelHostObject<Model>, unload, "unload"));
|
|
@@ -236,6 +242,7 @@ public:
|
|
|
236
242
|
ModelHostObject<Model>, synchronousHostFunction<&Model::streamFlush>,
|
|
237
243
|
"streamFlush"));
|
|
238
244
|
}
|
|
245
|
+
#endif
|
|
239
246
|
|
|
240
247
|
if constexpr (meta::HasGenerateFromString<Model>) {
|
|
241
248
|
addFunctions(
|
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
#include <rnexecutorch/Error.h>
|
|
8
8
|
#include <rnexecutorch/threads/GlobalThreadPool.h>
|
|
9
9
|
#include <runner/encoders/audio_encoder.h>
|
|
10
|
+
#ifdef RNE_ENABLE_OPENCV
|
|
10
11
|
#include <runner/encoders/vision_encoder.h>
|
|
12
|
+
#endif
|
|
11
13
|
#include <runner/multimodal_runner.h>
|
|
12
14
|
#include <runner/text_runner.h>
|
|
13
15
|
|
|
@@ -29,8 +31,17 @@ LLM::LLM(const std::string &modelSource, const std::string &tokenizerSource,
|
|
|
29
31
|
std::map<llm::MultimodalType, std::unique_ptr<llm::IEncoder>> encoders;
|
|
30
32
|
for (const auto &cap : capabilities) {
|
|
31
33
|
if (cap == "vision") {
|
|
34
|
+
#ifdef RNE_ENABLE_OPENCV
|
|
32
35
|
encoders[llm::MultimodalType::Image] =
|
|
33
36
|
std::make_unique<llm::VisionEncoder>(*module_);
|
|
37
|
+
#else
|
|
38
|
+
// The vision encoder decodes and resizes the image with opencv,
|
|
39
|
+
// so it is only there when opencv is.
|
|
40
|
+
throw RnExecutorchError(
|
|
41
|
+
RnExecutorchErrorCode::InvalidUserInput,
|
|
42
|
+
"The 'vision' capability requires the opencv native library, "
|
|
43
|
+
"which this app opted out of in package.json");
|
|
44
|
+
#endif
|
|
34
45
|
} else if (cap == "audio") {
|
|
35
46
|
encoders[llm::MultimodalType::Audio] =
|
|
36
47
|
std::make_unique<llm::AudioEncoder>(*module_);
|
|
@@ -4,10 +4,12 @@
|
|
|
4
4
|
#include <executorch/extension/threadpool/cpuinfo_utils.h>
|
|
5
5
|
#include <memory>
|
|
6
6
|
#include <mutex>
|
|
7
|
-
#include <opencv2/opencv.hpp>
|
|
8
7
|
#include <optional>
|
|
9
8
|
#include <rnexecutorch/Log.h>
|
|
10
9
|
#include <rnexecutorch/threads/HighPerformanceThreadPool.h>
|
|
10
|
+
#ifdef RNE_ENABLE_OPENCV
|
|
11
|
+
#include <opencv2/opencv.hpp>
|
|
12
|
+
#endif
|
|
11
13
|
|
|
12
14
|
namespace rnexecutorch::threads {
|
|
13
15
|
|
|
@@ -39,9 +41,11 @@ public:
|
|
|
39
41
|
numThreads, "threads");
|
|
40
42
|
instance = std::make_unique<HighPerformanceThreadPool>(numThreads.value(),
|
|
41
43
|
config);
|
|
44
|
+
#ifdef RNE_ENABLE_OPENCV
|
|
42
45
|
// Disable OpenCV's internal threading to prevent it from overriding our
|
|
43
46
|
// thread pool configuration, which would cause degraded performance
|
|
44
47
|
cv::setNumThreads(0);
|
|
48
|
+
#endif
|
|
45
49
|
});
|
|
46
50
|
}
|
|
47
51
|
|
package/legacy/src/index.ts
CHANGED
|
@@ -135,27 +135,11 @@ declare global {
|
|
|
135
135
|
}
|
|
136
136
|
// eslint-disable no-var
|
|
137
137
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
global.loadExecutorchModule == null ||
|
|
144
|
-
global.loadClassification == null ||
|
|
145
|
-
global.loadObjectDetection == null ||
|
|
146
|
-
global.loadPoseEstimation == null ||
|
|
147
|
-
global.loadTokenizerModule == null ||
|
|
148
|
-
global.loadTextEmbeddings == null ||
|
|
149
|
-
global.loadImageEmbeddings == null ||
|
|
150
|
-
global.loadVAD == null ||
|
|
151
|
-
global.loadLLM == null ||
|
|
152
|
-
global.loadPrivacyFilter == null ||
|
|
153
|
-
global.loadSpeechToText == null ||
|
|
154
|
-
global.loadTextToSpeechKokoro == null ||
|
|
155
|
-
global.loadOCR == null ||
|
|
156
|
-
global.loadVerticalOCR == null ||
|
|
157
|
-
global.__rne_isEmulator == null
|
|
158
|
-
) {
|
|
138
|
+
// Only the globals that are registered unconditionally. The per-task ones are
|
|
139
|
+
// absent by design when an app opts out of opencv or phonemis, so including
|
|
140
|
+
// them here would pin the condition to true and re-run install() on every
|
|
141
|
+
// module evaluation.
|
|
142
|
+
if (global.loadExecutorchModule == null || global.__rne_isEmulator == null) {
|
|
159
143
|
if (!ETInstallerNativeModule) {
|
|
160
144
|
throw new Error(
|
|
161
145
|
`Failed to install react-native-executorch: The native module could not be found.`
|
|
@@ -246,10 +246,15 @@ export async function createLLMChatSession(config, options = {}, runtime) {
|
|
|
246
246
|
finishReason
|
|
247
247
|
};
|
|
248
248
|
} catch (err) {
|
|
249
|
-
// Roll back history, KV cache, and active tensors to pre-turn state on
|
|
249
|
+
// Roll back history, KV cache, and active tensors to pre-turn state on
|
|
250
|
+
// failure. The rewind must never replace the error it is unwinding.
|
|
251
|
+
//
|
|
252
|
+
// Under `resetOnTurn` the pre-turn position IS zero: `initialPos` is
|
|
253
|
+
// read before the turn begins and the turn then zeroed the cache, so
|
|
254
|
+
// rewinding to it is out of range by construction.
|
|
250
255
|
history.length = turnStartIdx;
|
|
251
256
|
committed = initialCommitted;
|
|
252
|
-
runner.reset(initialPos);
|
|
257
|
+
runner.reset(resetOnTurn ? 0 : initialPos);
|
|
253
258
|
chatPreprocessor.clear();
|
|
254
259
|
throw err;
|
|
255
260
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["scheduleOnRN","RNBlobUtil","wrapAsync","createResourceScope","createLLMRunner","parseTokenizerConfig","createChatPreprocessor","generateChatTurnWorklet","runner","prompt","options","genConfig","eosToken","stopRegex","onToken","response","callback","token","test","stop","stats","generate","DEFAULT_MAX_TURNS","createLLMChatSession","config","runtime","scope","dispose","generationConfig","defaultGenerationConfig","initialMessages","toolOpts","resetOnTurn","modelPath","tokenizerPath","tokenizerConfigPath","modalities","preprocessorConfig","tools","parseToolCalls","maxToolTurns","tokenizerConfigStr","fs","readFile","tokenizerConfig","JSON","parse","chatTemplate","chatPreprocessorConfig","chatPreprocessor","track","prefill","history","committed","length","push","process","addGenPrompt","clear","generateChatTurn","sendMessage","message","turnGenConfig","generationOpts","initialCommitted","initialPos","getKVCacheState","pos","turnStartIdx","generationStatsList","role","content","reset","prefillStartMs","Date","now","toCommit","userPrompt","posAtEndOfUser","finishReason","currentTurn","uncommitted","prefillDurationMs","parsedTools","toolCalls","textContent","toolCall","tool","find","t","function","name","toolContent","execute","arguments","err","String","toolCallId","id","messages","slice","getHistory","error"],"sourceRoot":"../../../../../src","sources":["extensions/llm/tasks/llmChatSession.ts"],"mappings":";;AAAA;AACA;AACA;AACA;;AAEA,SAASA,YAAY,QAA6B,uBAAuB;AACzE,OAAOC,UAAU,MAAM,wBAAwB;AAE/C,SAASC,SAAS,QAAQ,0BAAuB;AACjD,SAASC,mBAAmB,QAAQ,2BAAwB;AAC5D,SACEC,eAAe,QAOV,iBAAc;AACrB,SAASC,oBAAoB,QAAQ,6BAA0B;AAC/D,SACEC,sBAAsB,QAIjB,8BAA2B;;AAGlC;AACA;AACA;AACA;;AAcA;AACA;AACA;AACA;;AAUA;AACA;AACA;AACA;;AAiBA;AACA;AACA;AACA;;AAcA;AACA;AACA;AACA;;AAsCA,SAASC,uBAAuBA,CAC9BC,MAAiB,EACjBC,MAAc,EACdC,OAKC,EACkE;EACnE,SAAS;;EACT,MAAM;IAAEC,SAAS;IAAEC,QAAQ;IAAEC,SAAS;IAAEC;EAAQ,CAAC,GAAGJ,OAAO;EAE3D,IAAIK,QAAQ,GAAG,EAAE;EAEjB,MAAMC,QAAQ,GAAIC,KAAa,IAAK;IAClC,IAAIA,KAAK,KAAKL,QAAQ,EAAE;IACxBG,QAAQ,IAAIE,KAAK;IAEjB,IAAIH,OAAO,EAAEd,YAAY,CAACc,OAAO,EAAEG,KAAK,CAAC;IACzC,IAAIJ,SAAS,EAAEK,IAAI,CAACH,Q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ACG,IAAI,CAAC;cACXe,IAAI,EAAE,MAAM;cACZ2B,UAAU,EAAEX,QAAQ,CAACY,EAAE;cACvBP,IAAI,EAAEL,QAAQ,CAACI,QAAQ,CAACC,IAAI;cAC5BpB,OAAO,EAAEqB;YACX,CAAC,CAAC;UACJ;UAEAnB,cAAc,GAAGC,IAAI,CAACC,GAAG,CAAC,CAAC;QAC7B;;QAEA;QACA;QACA,MAAMM,WAAW,GAAG7B,OAAO,CAACE,MAAM,GAAGD,SAAS;QAC9C,IAAI4B,WAAW,GAAG,CAAC,EAAE;UACnB,MAAMxE,MAAM,GAAGwC,gBAAgB,CAACO,OAAO,CAACJ,OAAO,EAAE6B,WAAW,EAAE;YAAExB,YAAY,EAAE;UAAM,CAAC,CAAC;UACtF,MAAMN,OAAO,CAAC1C,MAAM,CAAC;UACrBwC,gBAAgB,CAACS,KAAK,CAAC,CAAC;UACxBL,SAAS,GAAGD,OAAO,CAACE,MAAM;QAC5B;QAEA,OAAO;UAAE6C,QAAQ,EAAE/C,OAAO,CAACgD,KAAK,CAAChC,YAAY,CAAC;UAAEhD,KAAK,EAAEiD,mBAAmB;UAAEU;QAAa,CAAC;MAC5F,CAAC,CAAC,OAAOgB,GAAG,EAAE;QACZ;QACA3C,OAAO,CAACE,MAAM,GAAGc,YAAY;QAC7Bf,SAAS,GAAGW,gBAAgB;QAC5BxD,MAAM,CAACgE,KAAK,
|
|
1
|
+
{"version":3,"names":["scheduleOnRN","RNBlobUtil","wrapAsync","createResourceScope","createLLMRunner","parseTokenizerConfig","createChatPreprocessor","generateChatTurnWorklet","runner","prompt","options","genConfig","eosToken","stopRegex","onToken","response","callback","token","test","stop","stats","generate","DEFAULT_MAX_TURNS","createLLMChatSession","config","runtime","scope","dispose","generationConfig","defaultGenerationConfig","initialMessages","toolOpts","resetOnTurn","modelPath","tokenizerPath","tokenizerConfigPath","modalities","preprocessorConfig","tools","parseToolCalls","maxToolTurns","tokenizerConfigStr","fs","readFile","tokenizerConfig","JSON","parse","chatTemplate","chatPreprocessorConfig","chatPreprocessor","track","prefill","history","committed","length","push","process","addGenPrompt","clear","generateChatTurn","sendMessage","message","turnGenConfig","generationOpts","initialCommitted","initialPos","getKVCacheState","pos","turnStartIdx","generationStatsList","role","content","reset","prefillStartMs","Date","now","toCommit","userPrompt","posAtEndOfUser","finishReason","currentTurn","uncommitted","prefillDurationMs","parsedTools","toolCalls","textContent","toolCall","tool","find","t","function","name","toolContent","execute","arguments","err","String","toolCallId","id","messages","slice","getHistory","error"],"sourceRoot":"../../../../../src","sources":["extensions/llm/tasks/llmChatSession.ts"],"mappings":";;AAAA;AACA;AACA;AACA;;AAEA,SAASA,YAAY,QAA6B,uBAAuB;AACzE,OAAOC,UAAU,MAAM,wBAAwB;AAE/C,SAASC,SAAS,QAAQ,0BAAuB;AACjD,SAASC,mBAAmB,QAAQ,2BAAwB;AAC5D,SACEC,eAAe,QAOV,iBAAc;AACrB,SAASC,oBAAoB,QAAQ,6BAA0B;AAC/D,SACEC,sBAAsB,QAIjB,8BAA2B;;AAGlC;AACA;AACA;AACA;;AAcA;AACA;AACA;AACA;;AAUA;AACA;AACA;AACA;;AAiBA;AACA;AACA;AACA;;AAcA;AACA;AACA;AACA;;AAsCA,SAASC,uBAAuBA,CAC9BC,MAAiB,EACjBC,MAAc,EACdC,OAKC,EACkE;EACnE,SAAS;;EACT,MAAM;IAAEC,SAAS;IAAEC,QAAQ;IAAEC,SAAS;IAAEC;EAAQ,CAAC,GAAGJ,OAAO;EAE3D,IAAIK,QAAQ,GAAG,EAAE;EAEjB,MAAMC,QAAQ,GAAIC,KAAa,IAAK;IAClC,IAAIA,KAAK,KAAKL,QAAQ,EAAE;IACxBG,QAAQ,IAAIE,KAAK;IAEjB,IAAIH,OAAO,EAAEd,YAAY,CAACc,OAAO,EAAEG,KAAK,CAAC;IACzC,IAAIJ,SAAS,EAAEK,IAAI,CAACH,QAAQ,CAAC,EAAEP,MAAM,CAACW,IAAI,CAAC,CAAC;EAC9C,CAAC;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List":[]}
|
|
@@ -12,7 +12,7 @@ const DOWNLOAD_EVENT_ENDPOINT = 'https://ai.swmansion.com/telemetry/downloads/ap
|
|
|
12
12
|
// self-referencing import would need package `exports` support in the consuming
|
|
13
13
|
// bundler to load at all. A wrong value here is analytics noise; a failed
|
|
14
14
|
// import would break the bundle.
|
|
15
|
-
const LIB_VERSION = '0.10.
|
|
15
|
+
const LIB_VERSION = '0.10.2';
|
|
16
16
|
|
|
17
17
|
// Anonymous analytics are on by default; apps opt out via setTelemetryEnabled.
|
|
18
18
|
let telemetryEnabled = true;
|
|
@@ -33,25 +33,11 @@ export function cleanupExecutorch() {
|
|
|
33
33
|
ResourceFetcher.resetAdapter();
|
|
34
34
|
}
|
|
35
35
|
// eslint-disable no-var
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
global.loadClassification == null ||
|
|
42
|
-
global.loadObjectDetection == null ||
|
|
43
|
-
global.loadPoseEstimation == null ||
|
|
44
|
-
global.loadTokenizerModule == null ||
|
|
45
|
-
global.loadTextEmbeddings == null ||
|
|
46
|
-
global.loadImageEmbeddings == null ||
|
|
47
|
-
global.loadVAD == null ||
|
|
48
|
-
global.loadLLM == null ||
|
|
49
|
-
global.loadPrivacyFilter == null ||
|
|
50
|
-
global.loadSpeechToText == null ||
|
|
51
|
-
global.loadTextToSpeechKokoro == null ||
|
|
52
|
-
global.loadOCR == null ||
|
|
53
|
-
global.loadVerticalOCR == null ||
|
|
54
|
-
global.__rne_isEmulator == null) {
|
|
36
|
+
// Only the globals that are registered unconditionally. The per-task ones are
|
|
37
|
+
// absent by design when an app opts out of opencv or phonemis, so including
|
|
38
|
+
// them here would pin the condition to true and re-run install() on every
|
|
39
|
+
// module evaluation.
|
|
40
|
+
if (global.loadExecutorchModule == null || global.__rne_isEmulator == null) {
|
|
55
41
|
if (!ETInstallerNativeModule) {
|
|
56
42
|
throw new Error(`Failed to install react-native-executorch: The native module could not be found.`);
|
|
57
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An easy way to run AI models in React Native with ExecuTorch",
|
|
6
6
|
"main": "./lib/module/index.js",
|
|
@@ -142,7 +142,7 @@
|
|
|
142
142
|
"react": "*",
|
|
143
143
|
"react-native": "*",
|
|
144
144
|
"react-native-blob-util": "^0.24.0",
|
|
145
|
-
"react-native-worklets": "
|
|
145
|
+
"react-native-worklets": ">=0.10.0 <0.13.0"
|
|
146
146
|
},
|
|
147
147
|
"peerDependenciesMeta": {
|
|
148
148
|
"@kesha-antonov/react-native-background-downloader": {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
require "fileutils"
|
|
1
2
|
require "json"
|
|
2
3
|
|
|
3
4
|
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
@@ -6,19 +7,59 @@ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
|
6
7
|
# Falls back to all features enabled if the file doesn't exist (e.g. a fresh
|
|
7
8
|
# checkout where the native libs were provisioned manually).
|
|
8
9
|
rne_build_config_path = File.join(__dir__, "rne-build-config.json")
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
10
|
+
rne_build_config =
|
|
11
|
+
File.exist?(rne_build_config_path) ? JSON.parse(File.read(rne_build_config_path)) : {}
|
|
12
|
+
|
|
13
|
+
# Every flag reads `!= false`, so an absent file and an absent key both mean
|
|
14
|
+
# enabled. Keep the hash rather than branching on the file: `opencvPod` below
|
|
15
|
+
# is read from it too, and a nil `rne_build_config` there is a NoMethodError.
|
|
16
|
+
enable_opencv = rne_build_config["enableOpencv"] != false
|
|
17
|
+
enable_phonemis = rne_build_config["enablePhonemis"] != false
|
|
18
|
+
enable_xnnpack = rne_build_config["enableXnnpack"] != false
|
|
19
|
+
enable_coreml = rne_build_config["enableCoreml"] != false
|
|
20
|
+
enable_mlx = rne_build_config["enableMlx"] != false
|
|
21
|
+
|
|
22
|
+
# The native artifacts are not in the npm tarball - `package.json` excludes
|
|
23
|
+
# them and `scripts/download-libs.js` fetches them from the matching GitHub
|
|
24
|
+
# release in a postinstall hook. When a package manager skips that hook the
|
|
25
|
+
# install still looks clean, and so does `pod install`: CocoaPods never checks
|
|
26
|
+
# that a vendored framework exists. The build then fails minutes later with
|
|
27
|
+
#
|
|
28
|
+
# error: Build input files cannot be found:
|
|
29
|
+
# '.../XnnpackBackend.xcframework/ios-arm64-simulator/libXnnpackBackend.a'
|
|
30
|
+
#
|
|
31
|
+
# which names neither the cause nor the fix. Fail here instead, while the user
|
|
32
|
+
# is still looking at the install that caused it.
|
|
33
|
+
required_artifacts = { "ExecutorchLib.xcframework" => true }
|
|
34
|
+
required_artifacts["XnnpackBackend.xcframework"] = enable_xnnpack
|
|
35
|
+
required_artifacts["CoreMLBackend.xcframework"] = enable_coreml
|
|
36
|
+
required_artifacts["MLXBackend.xcframework"] = enable_mlx
|
|
37
|
+
|
|
38
|
+
missing = required_artifacts
|
|
39
|
+
.select { |_, required| required }
|
|
40
|
+
.keys
|
|
41
|
+
.map { |name| File.join(__dir__, "third-party/ios", name) }
|
|
42
|
+
.reject { |path| File.directory?(path) }
|
|
43
|
+
|
|
44
|
+
unless missing.empty?
|
|
45
|
+
# Pod::Informative renders as a plain `[!]` message rather than a backtrace.
|
|
46
|
+
raise(defined?(Pod::Informative) ? Pod::Informative : StandardError, <<~MESSAGE)
|
|
47
|
+
react-native-executorch is missing its native artifacts:
|
|
48
|
+
|
|
49
|
+
#{missing.map { |path| " #{path}" }.join("\n")}
|
|
50
|
+
|
|
51
|
+
They are downloaded by this package's postinstall hook, which your package
|
|
52
|
+
manager did not run. pnpm 10 and later block dependency build scripts by
|
|
53
|
+
default ("Ignored build scripts"), and so do `--ignore-scripts` and
|
|
54
|
+
`npm ci --ignore-scripts`. Re-run the hook, then `pod install` again:
|
|
55
|
+
|
|
56
|
+
pnpm approve-builds react-native-executorch # pnpm
|
|
57
|
+
npm rebuild react-native-executorch # npm
|
|
58
|
+
node node_modules/react-native-executorch/scripts/download-libs.js
|
|
59
|
+
|
|
60
|
+
If you provision the libraries yourself, put them under
|
|
61
|
+
third-party/ios/ before installing pods.
|
|
62
|
+
MESSAGE
|
|
22
63
|
end
|
|
23
64
|
|
|
24
65
|
Pod::Spec.new do |s|
|
|
@@ -95,8 +136,68 @@ Pod::Spec.new do |s|
|
|
|
95
136
|
# ==============================================================================
|
|
96
137
|
exclude_files += opencv_source_files unless enable_opencv
|
|
97
138
|
exclude_files += phonemis_source_files unless enable_phonemis
|
|
139
|
+
# ==============================================================================
|
|
140
|
+
# LEGACY SUPPORT: the legacy TTS models need phonemis too, and `legacy/cpp/**`
|
|
141
|
+
# above sweeps them in unconditionally. Without this they compile — the
|
|
142
|
+
# phonemis headers stay on HEADER_SEARCH_PATHS — and fail at link with
|
|
143
|
+
# undefined phonemis::Pipeline symbols.
|
|
144
|
+
# (Remove when react-native-executorch/legacy is dropped)
|
|
145
|
+
# ==============================================================================
|
|
146
|
+
unless enable_phonemis
|
|
147
|
+
exclude_files += ["legacy/cpp/rnexecutorch/models/text_to_speech/**/*.{cpp,c,h,hpp}"]
|
|
148
|
+
end
|
|
149
|
+
# ==============================================================================
|
|
150
|
+
# LEGACY SUPPORT: the same for opencv. The legacy vision models, the
|
|
151
|
+
# image/frame helpers they share and the multimodal LLM's vision encoder all
|
|
152
|
+
# compile against opencv2, which is not linked when opencv is off. Only the
|
|
153
|
+
# sources are excluded: the `Types.h` headers sitting next to them are
|
|
154
|
+
# opencv-free and `JsiConversions.h` includes them unconditionally.
|
|
155
|
+
# (Remove when react-native-executorch/legacy is dropped)
|
|
156
|
+
# ==============================================================================
|
|
157
|
+
unless enable_opencv
|
|
158
|
+
legacy_dir = "legacy/cpp/rnexecutorch"
|
|
159
|
+
exclude_files += [
|
|
160
|
+
"#{legacy_dir}/data_processing/ImageProcessing.cpp",
|
|
161
|
+
"#{legacy_dir}/models/VisionModel.cpp",
|
|
162
|
+
"#{legacy_dir}/utils/Frame*.cpp",
|
|
163
|
+
"legacy/cpp/runner/encoders/vision_encoder.cpp",
|
|
164
|
+
]
|
|
165
|
+
exclude_files += %w[
|
|
166
|
+
classification embeddings/image instance_segmentation object_detection ocr
|
|
167
|
+
pose_estimation semantic_segmentation style_transfer text_to_image vertical_ocr
|
|
168
|
+
].map { |task| "#{legacy_dir}/models/#{task}/**/*.{cpp,c}" }
|
|
169
|
+
end
|
|
170
|
+
# ==============================================================================
|
|
98
171
|
s.exclude_files = exclude_files
|
|
99
172
|
|
|
173
|
+
# --- Public headers ---
|
|
174
|
+
# `use_frameworks!` - set directly for Firebase, or through
|
|
175
|
+
# expo-build-properties' `useFrameworks: "static"` - makes CocoaPods build
|
|
176
|
+
# this pod as a framework, and Xcode's Headers build phase copies every
|
|
177
|
+
# *public* header into one flat `Headers/` directory. With no
|
|
178
|
+
# `public_header_files` every header in `source_files` is public, and the
|
|
179
|
+
# tree has 21 basenames that occur more than once (`Types.h` in eleven task
|
|
180
|
+
# directories, `constants.h` in thirteen phonemis ones), so the build fails
|
|
181
|
+
# at planning with `Multiple commands produce .../Headers/Types.h` before a
|
|
182
|
+
# single file compiles. See discussion #203.
|
|
183
|
+
#
|
|
184
|
+
# Only the Objective-C entry points have to be visible to the app. The C++
|
|
185
|
+
# headers are reached through the HEADER_SEARCH_PATHS below, so narrowing the
|
|
186
|
+
# public set costs nothing, and `__tests__/api/podspecPublicHeaders.test.ts`
|
|
187
|
+
# keeps it collision-free.
|
|
188
|
+
public_header_files = [
|
|
189
|
+
"ios/**/*.h",
|
|
190
|
+
]
|
|
191
|
+
# ==============================================================================
|
|
192
|
+
# LEGACY SUPPORT: include the legacy entry point
|
|
193
|
+
# (Remove when react-native-executorch/legacy is dropped)
|
|
194
|
+
# ==============================================================================
|
|
195
|
+
public_header_files += [
|
|
196
|
+
"legacy/ios/**/*.h",
|
|
197
|
+
]
|
|
198
|
+
# ==============================================================================
|
|
199
|
+
s.public_header_files = public_header_files
|
|
200
|
+
|
|
100
201
|
# --- Preprocessor flags ---
|
|
101
202
|
extra_compiler_flags = []
|
|
102
203
|
extra_compiler_flags << "-DRNE_ENABLE_OPENCV" if enable_opencv
|
|
@@ -143,6 +244,64 @@ Pod::Spec.new do |s|
|
|
|
143
244
|
'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'x86_64',
|
|
144
245
|
}
|
|
145
246
|
|
|
247
|
+
# iOS OpenCV is provided by a CocoaPod (not a downloaded tarball), normally
|
|
248
|
+
# our own opencv-rne.
|
|
249
|
+
#
|
|
250
|
+
# An app can already carry OpenCV through another library, and CocoaPods
|
|
251
|
+
# refuses to install two vendored frameworks with the same name:
|
|
252
|
+
#
|
|
253
|
+
# [!] The 'Pods-YourApp' target has frameworks with conflicting names:
|
|
254
|
+
# opencv2.xcframework
|
|
255
|
+
#
|
|
256
|
+
# react-native-fast-opencv is the one this happens with, and wanting both is
|
|
257
|
+
# reasonable: our inference API with their image transformations. So when it
|
|
258
|
+
# is installed alongside us we depend on the pod it vendors instead of our
|
|
259
|
+
# own, which leaves exactly one opencv2 in the project. We only use
|
|
260
|
+
# `opencv2/core.hpp` and `opencv2/imgproc.hpp`, so any OpenCV 4.x build
|
|
261
|
+
# serves. Set "opencvPod" in the package.json config block to override the
|
|
262
|
+
# choice in either direction.
|
|
263
|
+
external_opencv = false
|
|
264
|
+
if enable_opencv
|
|
265
|
+
detected_opencv_pod =
|
|
266
|
+
if Dir.exist?(File.join(__dir__, "..", "react-native-fast-opencv"))
|
|
267
|
+
"FastOpenCV-iOS"
|
|
268
|
+
else
|
|
269
|
+
"opencv-rne"
|
|
270
|
+
end
|
|
271
|
+
opencv_pod = rne_build_config["opencvPod"] || detected_opencv_pod
|
|
272
|
+
|
|
273
|
+
if opencv_pod == "opencv-rne"
|
|
274
|
+
s.dependency "opencv-rne", "~> 4.11.0"
|
|
275
|
+
else
|
|
276
|
+
Pod::UI.puts "[react-native-executorch] using #{opencv_pod} for OpenCV " \
|
|
277
|
+
"instead of opencv-rne, so the project holds one opencv2" if defined?(Pod::UI)
|
|
278
|
+
s.dependency opencv_pod
|
|
279
|
+
external_opencv = true
|
|
280
|
+
end
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
# Our own OpenCV headers ship under third-party/include and are newer than
|
|
284
|
+
# what another OpenCV pod vendors: react-native-fast-opencv carries 4.9, and
|
|
285
|
+
# compiling against ours while linking against theirs fails at link time on
|
|
286
|
+
# any signature that moved since (cvtColor gained an AlgorithmHint parameter
|
|
287
|
+
# in 4.10). Whoever provides the binary has to provide the headers, so with
|
|
288
|
+
# an external OpenCV the include root becomes a mirror of ours with opencv2
|
|
289
|
+
# left out, and `#include <opencv2/...>` resolves through their framework.
|
|
290
|
+
mirror_without_opencv = lambda do
|
|
291
|
+
source = File.join(__dir__, "third-party/include")
|
|
292
|
+
mirror = File.join(__dir__, "third-party/include-external-opencv")
|
|
293
|
+
FileUtils.rm_rf(mirror)
|
|
294
|
+
FileUtils.mkdir_p(mirror)
|
|
295
|
+
Dir.children(source).each do |entry|
|
|
296
|
+
next if entry == "opencv2"
|
|
297
|
+
FileUtils.ln_s(File.join(source, entry), File.join(mirror, entry))
|
|
298
|
+
end
|
|
299
|
+
"third-party/include-external-opencv"
|
|
300
|
+
end
|
|
301
|
+
|
|
302
|
+
third_party_include =
|
|
303
|
+
external_opencv ? mirror_without_opencv.call : "third-party/include"
|
|
304
|
+
|
|
146
305
|
s.pod_target_xcconfig = {
|
|
147
306
|
"USE_HEADERMAP" => "YES",
|
|
148
307
|
"CLANG_CXX_LANGUAGE_STANDARD" => "c++20",
|
|
@@ -158,7 +317,7 @@ Pod::Spec.new do |s|
|
|
|
158
317
|
# ==============================================================================
|
|
159
318
|
"\"$(PODS_TARGET_SRCROOT)/legacy/cpp\"",
|
|
160
319
|
# ==============================================================================
|
|
161
|
-
"\"$(PODS_TARGET_SRCROOT)
|
|
320
|
+
"\"$(PODS_TARGET_SRCROOT)/#{third_party_include}\"",
|
|
162
321
|
"\"$(PODS_TARGET_SRCROOT)/third-party/include/cpuinfo\"",
|
|
163
322
|
"\"$(PODS_TARGET_SRCROOT)/third-party/include/pthreadpool\"",
|
|
164
323
|
"\"$(PODS_TARGET_SRCROOT)/third-party/include/executorch/extension/llm/tokenizers/include\"",
|
|
@@ -189,13 +348,23 @@ Pod::Spec.new do |s|
|
|
|
189
348
|
# resource path. `s.ios.resource` achieves that via CocoaPods' resource copy.
|
|
190
349
|
s.ios.resource = "third-party/ios/libs/executorch/mlx.metallib" if enable_mlx
|
|
191
350
|
|
|
351
|
+
# An app that turns on `use_frameworks!` without naming a linkage gets the
|
|
352
|
+
# default, dynamic - which is what Firebase's own setup instructions show.
|
|
353
|
+
# CocoaPods then refuses to install at all, because a dynamic framework may
|
|
354
|
+
# not carry statically linked binaries and opencv-rne vendors one:
|
|
355
|
+
#
|
|
356
|
+
# [!] The 'Pods-YourApp' target has transitive dependencies that include
|
|
357
|
+
# statically linked binaries: (.../opencv-rne/opencv2.xcframework)
|
|
358
|
+
#
|
|
359
|
+
# Declaring the pod a static framework resolves that without the app having
|
|
360
|
+
# to spell out `:linkage => :static`, and is inert when the pod is built as a
|
|
361
|
+
# static library, which is what happens with no `use_frameworks!` at all.
|
|
362
|
+
s.static_framework = true
|
|
363
|
+
|
|
192
364
|
# Backend xcframeworks are linked via force_load in OTHER_LDFLAGS (needed to
|
|
193
365
|
# preserve __attribute__((constructor)) backend registrations). Only
|
|
194
366
|
# ExecutorchLib goes in vendored_frameworks to avoid duplicate symbol errors.
|
|
195
367
|
s.ios.vendored_frameworks = ["third-party/ios/ExecutorchLib.xcframework"]
|
|
196
368
|
|
|
197
|
-
# iOS OpenCV is provided by the opencv-rne CocoaPod (not a downloaded tarball).
|
|
198
|
-
s.dependency "opencv-rne", "~> 4.11.0" if enable_opencv
|
|
199
|
-
|
|
200
369
|
install_modules_dependencies(s)
|
|
201
370
|
end
|
package/scripts/download-libs.js
CHANGED
|
@@ -172,32 +172,67 @@ const FEATURE_MAP = {
|
|
|
172
172
|
tokenizer: { backends: [], libs: [] },
|
|
173
173
|
};
|
|
174
174
|
|
|
175
|
-
|
|
176
|
-
|
|
175
|
+
/**
|
|
176
|
+
* The `react-native-executorch` block, and the package.json it came from.
|
|
177
|
+
*
|
|
178
|
+
* Two places are tried, in order:
|
|
179
|
+
*
|
|
180
|
+
* 1. INIT_CWD - where the install was invoked. For a single-app project that
|
|
181
|
+
* is the app itself.
|
|
182
|
+
* 2. Each package.json above this package. In a workspace, `yarn install` is
|
|
183
|
+
* run at the root, so INIT_CWD points there and a block in
|
|
184
|
+
* `apps/mobile/package.json` would never be seen. When the app keeps its
|
|
185
|
+
* own node_modules (pnpm, nohoist), walking up from here lands on the app.
|
|
186
|
+
*
|
|
187
|
+
* A hoisted workspace resolves to the root either way, which is where the block
|
|
188
|
+
* has to live in that layout - there is no way to tell which of several apps a
|
|
189
|
+
* root install was meant for.
|
|
190
|
+
* @returns The block and the path of the package.json holding it, or both
|
|
191
|
+
* `undefined` when no manifest declares one.
|
|
192
|
+
*/
|
|
193
|
+
function findUserConfig() {
|
|
194
|
+
const candidates = [];
|
|
195
|
+
const initCwd = process.env.INIT_CWD || process.env.npm_config_local_prefix;
|
|
196
|
+
if (initCwd) candidates.push(initCwd);
|
|
197
|
+
|
|
198
|
+
// `__dirname` is <somewhere>/node_modules/react-native-executorch/scripts.
|
|
199
|
+
let dir = path.resolve(__dirname, '..', '..', '..');
|
|
200
|
+
for (let i = 0; i < 6; i++) {
|
|
201
|
+
if (!candidates.includes(dir)) candidates.push(dir);
|
|
202
|
+
const parent = path.dirname(dir);
|
|
203
|
+
if (parent === dir) break;
|
|
204
|
+
dir = parent;
|
|
205
|
+
}
|
|
177
206
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
207
|
+
for (const root of candidates) {
|
|
208
|
+
const manifest = path.join(root, 'package.json');
|
|
209
|
+
let parsed;
|
|
210
|
+
try {
|
|
211
|
+
parsed = JSON.parse(fs.readFileSync(manifest, 'utf8'));
|
|
212
|
+
} catch {
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
if (parsed['react-native-executorch'] !== undefined) {
|
|
216
|
+
return { config: parsed['react-native-executorch'], manifest };
|
|
217
|
+
}
|
|
185
218
|
}
|
|
219
|
+
return { config: undefined, manifest: undefined };
|
|
220
|
+
}
|
|
186
221
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
'[react-native-executorch] Could not read app package.json, enabling all backends + libs.'
|
|
222
|
+
function readUserConfig() {
|
|
223
|
+
const allOn = () => ({ backends: [...ALL_BACKENDS], libs: [...ALL_LIBS], opencvPod: undefined });
|
|
224
|
+
|
|
225
|
+
const { config: rneConfig, manifest } = findUserConfig();
|
|
226
|
+
|
|
227
|
+
if (rneConfig === undefined) {
|
|
228
|
+
console.log(
|
|
229
|
+
'[react-native-executorch] No `react-native-executorch` block found; enabling all backends + libs.'
|
|
196
230
|
);
|
|
197
231
|
return allOn();
|
|
198
232
|
}
|
|
199
|
-
|
|
200
|
-
|
|
233
|
+
// Which manifest won matters when it is not the one the user edited - the
|
|
234
|
+
// usual monorepo surprise.
|
|
235
|
+
console.log(`[react-native-executorch] Read build config from ${manifest}`);
|
|
201
236
|
|
|
202
237
|
if (rneConfig.extras !== undefined) {
|
|
203
238
|
throw new Error(
|
|
@@ -236,10 +271,10 @@ function readUserConfig() {
|
|
|
236
271
|
}
|
|
237
272
|
}
|
|
238
273
|
|
|
239
|
-
return { backends: [...backends], libs: [...libs] };
|
|
274
|
+
return { backends: [...backends], libs: [...libs], opencvPod: rneConfig.opencvPod };
|
|
240
275
|
}
|
|
241
276
|
|
|
242
|
-
function writeBuildConfig({ backends, libs }) {
|
|
277
|
+
function writeBuildConfig({ backends, libs, opencvPod }) {
|
|
243
278
|
const config = {
|
|
244
279
|
enableOpencv: libs.includes('opencv'),
|
|
245
280
|
enablePhonemis: libs.includes('phonemis'),
|
|
@@ -248,6 +283,10 @@ function writeBuildConfig({ backends, libs }) {
|
|
|
248
283
|
enableMlx: backends.includes('mlx'),
|
|
249
284
|
enableVulkan: backends.includes('vulkan'),
|
|
250
285
|
};
|
|
286
|
+
// Which pod provides opencv2 on iOS. Only set when the app asks for a
|
|
287
|
+
// specific one; otherwise the podspec picks, preferring an OpenCV the app
|
|
288
|
+
// already carries so two frameworks named opencv2 never meet.
|
|
289
|
+
if (opencvPod !== undefined) config.opencvPod = opencvPod;
|
|
251
290
|
fs.writeFileSync(
|
|
252
291
|
path.join(PACKAGE_ROOT, 'rne-build-config.json'),
|
|
253
292
|
JSON.stringify(config, null, 2)
|
|
@@ -497,4 +536,4 @@ if (require.main === module) {
|
|
|
497
536
|
});
|
|
498
537
|
}
|
|
499
538
|
|
|
500
|
-
module.exports = { ALL_BACKENDS, ALL_LIBS, FEATURE_MAP };
|
|
539
|
+
module.exports = { ALL_BACKENDS, ALL_LIBS, FEATURE_MAP, findUserConfig, readUserConfig };
|
|
@@ -330,10 +330,15 @@ export async function createLLMChatSession(
|
|
|
330
330
|
|
|
331
331
|
return { messages: history.slice(turnStartIdx), stats: generationStatsList, finishReason };
|
|
332
332
|
} catch (err) {
|
|
333
|
-
// Roll back history, KV cache, and active tensors to pre-turn state on
|
|
333
|
+
// Roll back history, KV cache, and active tensors to pre-turn state on
|
|
334
|
+
// failure. The rewind must never replace the error it is unwinding.
|
|
335
|
+
//
|
|
336
|
+
// Under `resetOnTurn` the pre-turn position IS zero: `initialPos` is
|
|
337
|
+
// read before the turn begins and the turn then zeroed the cache, so
|
|
338
|
+
// rewinding to it is out of range by construction.
|
|
334
339
|
history.length = turnStartIdx;
|
|
335
340
|
committed = initialCommitted;
|
|
336
|
-
runner.reset(initialPos);
|
|
341
|
+
runner.reset(resetOnTurn ? 0 : initialPos);
|
|
337
342
|
chatPreprocessor.clear();
|
|
338
343
|
throw err;
|
|
339
344
|
}
|
package/src/fetcher/telemetry.ts
CHANGED
|
@@ -10,7 +10,7 @@ const DOWNLOAD_EVENT_ENDPOINT = 'https://ai.swmansion.com/telemetry/downloads/ap
|
|
|
10
10
|
// self-referencing import would need package `exports` support in the consuming
|
|
11
11
|
// bundler to load at all. A wrong value here is analytics noise; a failed
|
|
12
12
|
// import would break the bundle.
|
|
13
|
-
const LIB_VERSION = '0.10.
|
|
13
|
+
const LIB_VERSION = '0.10.2';
|
|
14
14
|
|
|
15
15
|
// Anonymous analytics are on by default; apps opt out via setTelemetryEnabled.
|
|
16
16
|
let telemetryEnabled = true;
|