@runanywhere/core 0.16.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/RunAnywhereCore.podspec +130 -0
- package/android/CMakeLists.txt +92 -0
- package/android/build.gradle +321 -0
- package/android/consumer-rules.pro +5 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/cpp/cpp-adapter.cpp +271 -0
- package/android/src/main/include/rac/backends/rac_llm_llamacpp.h +218 -0
- package/android/src/main/include/rac/backends/rac_stt_onnx.h +99 -0
- package/android/src/main/include/rac/backends/rac_stt_whispercpp.h +153 -0
- package/android/src/main/include/rac/backends/rac_tts_onnx.h +71 -0
- package/android/src/main/include/rac/backends/rac_vad_onnx.h +84 -0
- package/android/src/main/include/rac/core/capabilities/rac_lifecycle.h +290 -0
- package/android/src/main/include/rac/core/rac_analytics_events.h +610 -0
- package/android/src/main/include/rac/core/rac_audio_utils.h +88 -0
- package/android/src/main/include/rac/core/rac_component_types.h +160 -0
- package/android/src/main/include/rac/core/rac_core.h +331 -0
- package/android/src/main/include/rac/core/rac_error.h +469 -0
- package/android/src/main/include/rac/core/rac_events.h +334 -0
- package/android/src/main/include/rac/core/rac_logger.h +416 -0
- package/android/src/main/include/rac/core/rac_platform_adapter.h +340 -0
- package/android/src/main/include/rac/core/rac_sdk_state.h +292 -0
- package/android/src/main/include/rac/core/rac_structured_error.h +594 -0
- package/android/src/main/include/rac/core/rac_types.h +264 -0
- package/android/src/main/include/rac/features/llm/rac_llm.h +17 -0
- package/android/src/main/include/rac/features/llm/rac_llm_analytics.h +188 -0
- package/android/src/main/include/rac/features/llm/rac_llm_component.h +228 -0
- package/android/src/main/include/rac/features/llm/rac_llm_events.h +215 -0
- package/android/src/main/include/rac/features/llm/rac_llm_metrics.h +402 -0
- package/android/src/main/include/rac/features/llm/rac_llm_service.h +163 -0
- package/android/src/main/include/rac/features/llm/rac_llm_structured_output.h +141 -0
- package/android/src/main/include/rac/features/llm/rac_llm_types.h +384 -0
- package/android/src/main/include/rac/features/platform/rac_llm_platform.h +204 -0
- package/android/src/main/include/rac/features/platform/rac_tts_platform.h +197 -0
- package/android/src/main/include/rac/features/stt/rac_stt.h +17 -0
- package/android/src/main/include/rac/features/stt/rac_stt_analytics.h +204 -0
- package/android/src/main/include/rac/features/stt/rac_stt_component.h +162 -0
- package/android/src/main/include/rac/features/stt/rac_stt_events.h +62 -0
- package/android/src/main/include/rac/features/stt/rac_stt_service.h +154 -0
- package/android/src/main/include/rac/features/stt/rac_stt_types.h +389 -0
- package/android/src/main/include/rac/features/tts/rac_tts.h +17 -0
- package/android/src/main/include/rac/features/tts/rac_tts_analytics.h +181 -0
- package/android/src/main/include/rac/features/tts/rac_tts_component.h +158 -0
- package/android/src/main/include/rac/features/tts/rac_tts_events.h +54 -0
- package/android/src/main/include/rac/features/tts/rac_tts_service.h +162 -0
- package/android/src/main/include/rac/features/tts/rac_tts_types.h +374 -0
- package/android/src/main/include/rac/features/vad/rac_vad.h +17 -0
- package/android/src/main/include/rac/features/vad/rac_vad_analytics.h +236 -0
- package/android/src/main/include/rac/features/vad/rac_vad_component.h +185 -0
- package/android/src/main/include/rac/features/vad/rac_vad_energy.h +443 -0
- package/android/src/main/include/rac/features/vad/rac_vad_events.h +76 -0
- package/android/src/main/include/rac/features/vad/rac_vad_service.h +167 -0
- package/android/src/main/include/rac/features/vad/rac_vad_types.h +244 -0
- package/android/src/main/include/rac/features/voice_agent/rac_voice_agent.h +612 -0
- package/android/src/main/include/rac/infrastructure/device/rac_device_manager.h +176 -0
- package/android/src/main/include/rac/infrastructure/download/rac_download.h +418 -0
- package/android/src/main/include/rac/infrastructure/events/rac_events.h +177 -0
- package/android/src/main/include/rac/infrastructure/model_management/rac_model_assignment.h +169 -0
- package/android/src/main/include/rac/infrastructure/model_management/rac_model_paths.h +258 -0
- package/android/src/main/include/rac/infrastructure/model_management/rac_model_registry.h +357 -0
- package/android/src/main/include/rac/infrastructure/model_management/rac_model_strategy.h +374 -0
- package/android/src/main/include/rac/infrastructure/model_management/rac_model_types.h +613 -0
- package/android/src/main/include/rac/infrastructure/network/rac_api_types.h +335 -0
- package/android/src/main/include/rac/infrastructure/network/rac_auth_manager.h +252 -0
- package/android/src/main/include/rac/infrastructure/network/rac_dev_config.h +85 -0
- package/android/src/main/include/rac/infrastructure/network/rac_endpoints.h +102 -0
- package/android/src/main/include/rac/infrastructure/network/rac_environment.h +220 -0
- package/android/src/main/include/rac/infrastructure/network/rac_http_client.h +233 -0
- package/android/src/main/include/rac/infrastructure/storage/rac_storage_analyzer.h +286 -0
- package/android/src/main/include/rac/infrastructure/telemetry/rac_telemetry_manager.h +206 -0
- package/android/src/main/include/rac/infrastructure/telemetry/rac_telemetry_types.h +234 -0
- package/android/src/main/java/com/margelo/nitro/runanywhere/ArchiveUtility.kt +308 -0
- package/android/src/main/java/com/margelo/nitro/runanywhere/HybridRunAnywhereDeviceInfo.kt +229 -0
- package/android/src/main/java/com/margelo/nitro/runanywhere/PlatformAdapterBridge.kt +392 -0
- package/android/src/main/java/com/margelo/nitro/runanywhere/RunAnywhereCorePackage.kt +28 -0
- package/android/src/main/java/com/margelo/nitro/runanywhere/SDKLogger.kt +357 -0
- package/android/src/main/java/com/margelo/nitro/runanywhere/SecureStorageManager.kt +147 -0
- package/android/src/main/jniLibs/arm64-v8a/libc++_shared.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libomp.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/librac_commons.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/librunanywhere_jni.so +0 -0
- package/cpp/HybridRunAnywhereCore.cpp +2505 -0
- package/cpp/HybridRunAnywhereCore.hpp +271 -0
- package/cpp/bridges/AuthBridge.cpp +209 -0
- package/cpp/bridges/AuthBridge.hpp +157 -0
- package/cpp/bridges/DeviceBridge.cpp +257 -0
- package/cpp/bridges/DeviceBridge.hpp +155 -0
- package/cpp/bridges/DownloadBridge.cpp +299 -0
- package/cpp/bridges/DownloadBridge.hpp +197 -0
- package/cpp/bridges/EventBridge.cpp +125 -0
- package/cpp/bridges/EventBridge.hpp +139 -0
- package/cpp/bridges/HTTPBridge.cpp +96 -0
- package/cpp/bridges/HTTPBridge.hpp +144 -0
- package/cpp/bridges/InitBridge.cpp +1273 -0
- package/cpp/bridges/InitBridge.hpp +306 -0
- package/cpp/bridges/ModelRegistryBridge.cpp +394 -0
- package/cpp/bridges/ModelRegistryBridge.hpp +177 -0
- package/cpp/bridges/StorageBridge.cpp +269 -0
- package/cpp/bridges/StorageBridge.hpp +172 -0
- package/cpp/bridges/TelemetryBridge.cpp +352 -0
- package/cpp/bridges/TelemetryBridge.hpp +126 -0
- package/ios/.testlocal +0 -0
- package/ios/ArchiveUtility.swift +526 -0
- package/ios/ArchiveUtilityBridge.m +52 -0
- package/ios/AudioDecoder.h +38 -0
- package/ios/AudioDecoder.m +162 -0
- package/ios/Binaries/RACommons.xcframework/Info.plist +44 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/RACommons.h +67 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_analytics_events.h +610 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_api_types.h +335 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_audio_utils.h +88 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_auth_manager.h +252 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_component_types.h +160 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_core.h +331 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_dev_config.h +85 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_device_manager.h +176 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_download.h +418 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_endpoints.h +102 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_environment.h +220 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_error.h +469 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_events.h +177 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_http_client.h +233 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_lifecycle.h +290 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_llm.h +17 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_llm_analytics.h +188 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_llm_component.h +228 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_llm_events.h +215 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_llm_llamacpp.h +218 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_llm_metrics.h +402 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_llm_platform.h +204 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_llm_service.h +163 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_llm_structured_output.h +141 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_llm_types.h +384 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_logger.h +416 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_model_assignment.h +169 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_model_paths.h +258 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_model_registry.h +357 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_model_strategy.h +374 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_model_types.h +613 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_platform_adapter.h +340 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_sdk_state.h +292 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_storage_analyzer.h +286 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_structured_error.h +594 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_stt.h +17 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_stt_analytics.h +204 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_stt_component.h +162 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_stt_events.h +62 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_stt_onnx.h +99 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_stt_service.h +154 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_stt_types.h +389 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_stt_whispercpp.h +153 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_telemetry_manager.h +206 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_telemetry_types.h +234 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_tts.h +17 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_tts_analytics.h +181 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_tts_component.h +158 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_tts_events.h +54 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_tts_onnx.h +71 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_tts_platform.h +197 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_tts_service.h +162 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_tts_types.h +374 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_types.h +264 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_vad.h +17 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_vad_analytics.h +236 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_vad_component.h +185 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_vad_energy.h +443 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_vad_events.h +76 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_vad_onnx.h +84 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_vad_service.h +167 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_vad_types.h +244 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_voice_agent.h +612 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Info.plist +11 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Modules/module.modulemap +5 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/RACommons +0 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/RACommons.h +67 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_analytics_events.h +610 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_api_types.h +335 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_audio_utils.h +88 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_auth_manager.h +252 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_component_types.h +160 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_core.h +331 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_dev_config.h +85 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_device_manager.h +176 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_download.h +418 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_endpoints.h +102 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_environment.h +220 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_error.h +469 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_events.h +177 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_http_client.h +233 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_lifecycle.h +290 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_llm.h +17 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_llm_analytics.h +188 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_llm_component.h +228 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_llm_events.h +215 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_llm_llamacpp.h +218 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_llm_metrics.h +402 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_llm_platform.h +204 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_llm_service.h +163 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_llm_structured_output.h +141 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_llm_types.h +384 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_logger.h +416 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_model_assignment.h +169 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_model_paths.h +258 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_model_registry.h +357 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_model_strategy.h +374 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_model_types.h +613 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_platform_adapter.h +340 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_sdk_state.h +292 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_storage_analyzer.h +286 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_structured_error.h +594 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_stt.h +17 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_stt_analytics.h +204 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_stt_component.h +162 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_stt_events.h +62 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_stt_onnx.h +99 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_stt_service.h +154 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_stt_types.h +389 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_stt_whispercpp.h +153 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_telemetry_manager.h +206 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_telemetry_types.h +234 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_tts.h +17 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_tts_analytics.h +181 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_tts_component.h +158 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_tts_events.h +54 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_tts_onnx.h +71 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_tts_platform.h +197 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_tts_service.h +162 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_tts_types.h +374 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_types.h +264 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_vad.h +17 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_vad_analytics.h +236 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_vad_component.h +185 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_vad_energy.h +443 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_vad_events.h +76 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_vad_onnx.h +84 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_vad_service.h +167 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_vad_types.h +244 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_voice_agent.h +612 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Info.plist +11 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Modules/module.modulemap +5 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/RACommons +0 -0
- package/ios/HybridRunAnywhereDeviceInfo.swift +214 -0
- package/ios/KeychainManager.swift +116 -0
- package/ios/PlatformAdapter.swift +100 -0
- package/ios/PlatformAdapterBridge.h +152 -0
- package/ios/PlatformAdapterBridge.m +570 -0
- package/ios/RNSDKLoggerBridge.h +41 -0
- package/ios/RNSDKLoggerBridge.m +66 -0
- package/ios/SDKLogger.swift +329 -0
- package/nitro.json +20 -0
- package/nitrogen/generated/.gitattributes +1 -0
- package/nitrogen/generated/android/c++/JHybridRunAnywhereDeviceInfoSpec.cpp +257 -0
- package/nitrogen/generated/android/c++/JHybridRunAnywhereDeviceInfoSpec.hpp +77 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/runanywhere/HybridRunAnywhereDeviceInfoSpec.kt +106 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/runanywhere/runanywherecoreOnLoad.kt +35 -0
- package/nitrogen/generated/android/runanywherecore+autolinking.cmake +82 -0
- package/nitrogen/generated/android/runanywherecore+autolinking.gradle +27 -0
- package/nitrogen/generated/android/runanywherecoreOnLoad.cpp +54 -0
- package/nitrogen/generated/android/runanywherecoreOnLoad.hpp +25 -0
- package/nitrogen/generated/ios/RunAnywhereCore+autolinking.rb +60 -0
- package/nitrogen/generated/ios/RunAnywhereCore-Swift-Cxx-Bridge.cpp +65 -0
- package/nitrogen/generated/ios/RunAnywhereCore-Swift-Cxx-Bridge.hpp +197 -0
- package/nitrogen/generated/ios/RunAnywhereCore-Swift-Cxx-Umbrella.hpp +45 -0
- package/nitrogen/generated/ios/RunAnywhereCoreAutolinking.mm +43 -0
- package/nitrogen/generated/ios/RunAnywhereCoreAutolinking.swift +25 -0
- package/nitrogen/generated/ios/c++/HybridRunAnywhereDeviceInfoSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridRunAnywhereDeviceInfoSpecSwift.hpp +173 -0
- package/nitrogen/generated/ios/swift/Func_void_bool.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_double.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__string.swift +47 -0
- package/nitrogen/generated/ios/swift/HybridRunAnywhereDeviceInfoSpec.swift +68 -0
- package/nitrogen/generated/ios/swift/HybridRunAnywhereDeviceInfoSpec_cxx.swift +366 -0
- package/nitrogen/generated/shared/c++/HybridRunAnywhereCoreSpec.cpp +92 -0
- package/nitrogen/generated/shared/c++/HybridRunAnywhereCoreSpec.hpp +138 -0
- package/nitrogen/generated/shared/c++/HybridRunAnywhereDeviceInfoSpec.cpp +33 -0
- package/nitrogen/generated/shared/c++/HybridRunAnywhereDeviceInfoSpec.hpp +75 -0
- package/package.json +76 -0
- package/react-native.config.js +14 -0
- package/src/Features/VoiceSession/AudioCaptureManager.ts +286 -0
- package/src/Features/VoiceSession/AudioPlaybackManager.ts +300 -0
- package/src/Features/VoiceSession/VoiceSessionHandle.ts +530 -0
- package/src/Features/VoiceSession/index.ts +20 -0
- package/src/Features/index.ts +7 -0
- package/src/Foundation/Constants/SDKConstants.ts +47 -0
- package/src/Foundation/Constants/index.ts +8 -0
- package/src/Foundation/DependencyInjection/ServiceContainer.ts +154 -0
- package/src/Foundation/DependencyInjection/ServiceRegistry.ts +51 -0
- package/src/Foundation/DependencyInjection/index.ts +6 -0
- package/src/Foundation/ErrorTypes/ErrorCategory.ts +184 -0
- package/src/Foundation/ErrorTypes/ErrorCodes.ts +151 -0
- package/src/Foundation/ErrorTypes/ErrorContext.ts +201 -0
- package/src/Foundation/ErrorTypes/SDKError.ts +507 -0
- package/src/Foundation/ErrorTypes/index.ts +57 -0
- package/src/Foundation/Initialization/InitializationPhase.ts +85 -0
- package/src/Foundation/Initialization/InitializationState.ts +168 -0
- package/src/Foundation/Initialization/index.ts +26 -0
- package/src/Foundation/Logging/Destinations/NativeLogBridge.ts +147 -0
- package/src/Foundation/Logging/Destinations/SentryDestination.ts +209 -0
- package/src/Foundation/Logging/Logger/SDKLogger.ts +232 -0
- package/src/Foundation/Logging/Models/LogLevel.ts +36 -0
- package/src/Foundation/Logging/Models/LoggingConfiguration.ts +117 -0
- package/src/Foundation/Logging/Services/LoggingManager.ts +407 -0
- package/src/Foundation/Logging/index.ts +59 -0
- package/src/Foundation/Security/DeviceIdentity.ts +92 -0
- package/src/Foundation/Security/SecureStorageError.ts +132 -0
- package/src/Foundation/Security/SecureStorageKeys.ts +35 -0
- package/src/Foundation/Security/SecureStorageService.ts +449 -0
- package/src/Foundation/Security/index.ts +17 -0
- package/src/Foundation/index.ts +26 -0
- package/src/Infrastructure/Events/EventPublisher.ts +165 -0
- package/src/Infrastructure/Events/SDKEvent.ts +214 -0
- package/src/Infrastructure/Events/index.ts +15 -0
- package/src/Infrastructure/index.ts +9 -0
- package/src/Public/Events/EventBus.ts +488 -0
- package/src/Public/Events/index.ts +8 -0
- package/src/Public/Extensions/RunAnywhere+Logging.ts +51 -0
- package/src/Public/Extensions/RunAnywhere+Models.ts +392 -0
- package/src/Public/Extensions/RunAnywhere+STT.ts +424 -0
- package/src/Public/Extensions/RunAnywhere+Storage.ts +151 -0
- package/src/Public/Extensions/RunAnywhere+StructuredOutput.ts +316 -0
- package/src/Public/Extensions/RunAnywhere+TTS.ts +430 -0
- package/src/Public/Extensions/RunAnywhere+TextGeneration.ts +320 -0
- package/src/Public/Extensions/RunAnywhere+VAD.ts +359 -0
- package/src/Public/Extensions/RunAnywhere+VoiceAgent.ts +225 -0
- package/src/Public/Extensions/RunAnywhere+VoiceSession.ts +155 -0
- package/src/Public/Extensions/index.ts +126 -0
- package/src/Public/RunAnywhere.ts +695 -0
- package/src/index.ts +238 -0
- package/src/native/NativeRunAnywhereCore.ts +291 -0
- package/src/native/NativeRunAnywhereModule.ts +32 -0
- package/src/native/index.ts +21 -0
- package/src/services/DownloadService.ts +282 -0
- package/src/services/FileSystem.ts +810 -0
- package/src/services/ModelRegistry.ts +246 -0
- package/src/services/Network/APIEndpoints.ts +84 -0
- package/src/services/Network/HTTPService.ts +479 -0
- package/src/services/Network/NetworkConfiguration.ts +130 -0
- package/src/services/Network/TelemetryService.ts +318 -0
- package/src/services/Network/index.ts +29 -0
- package/src/services/SystemTTSService.ts +130 -0
- package/src/services/index.ts +66 -0
- package/src/specs/RunAnywhereCore.nitro.ts +627 -0
- package/src/specs/RunAnywhereDeviceInfo.nitro.ts +73 -0
- package/src/types/LLMTypes.ts +127 -0
- package/src/types/STTTypes.ts +124 -0
- package/src/types/StructuredOutputTypes.ts +156 -0
- package/src/types/TTSTypes.ts +126 -0
- package/src/types/VADTypes.ts +70 -0
- package/src/types/VoiceAgentTypes.ts +182 -0
- package/src/types/enums.ts +258 -0
- package/src/types/events.ts +337 -0
- package/src/types/external.d.ts +142 -0
- package/src/types/index.ts +146 -0
- package/src/types/models.ts +579 -0
|
@@ -0,0 +1,810 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FileSystem.ts
|
|
3
|
+
*
|
|
4
|
+
* File system service using react-native-fs for model downloads and storage.
|
|
5
|
+
* Matches Swift SDK's path structure: Documents/RunAnywhere/Models/{framework}/{modelId}/
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { Platform } from 'react-native';
|
|
9
|
+
import { SDKLogger } from '../Foundation/Logging/Logger/SDKLogger';
|
|
10
|
+
|
|
11
|
+
const logger = new SDKLogger('FileSystem');
|
|
12
|
+
|
|
13
|
+
// Lazy-loaded native module getter to avoid initialization order issues
|
|
14
|
+
let _nativeModuleGetter: (() => { extractArchive: (archivePath: string, destPath: string) => Promise<boolean> }) | null = null;
|
|
15
|
+
|
|
16
|
+
function getNativeModule(): { extractArchive: (archivePath: string, destPath: string) => Promise<boolean> } | null {
|
|
17
|
+
if (_nativeModuleGetter === null) {
|
|
18
|
+
try {
|
|
19
|
+
// Dynamic require to avoid circular dependency and initialization order issues
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
21
|
+
const { requireNativeModule, isNativeModuleAvailable } = require('../native/NativeRunAnywhereCore');
|
|
22
|
+
if (isNativeModuleAvailable()) {
|
|
23
|
+
_nativeModuleGetter = () => requireNativeModule();
|
|
24
|
+
} else {
|
|
25
|
+
logger.warning('Native module not available for archive extraction');
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
} catch (e) {
|
|
29
|
+
logger.error('Failed to load native module:', { error: e });
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return _nativeModuleGetter ? _nativeModuleGetter() : null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Types for react-native-fs (defined locally to avoid module resolution issues)
|
|
37
|
+
interface RNFSDownloadBeginCallbackResult {
|
|
38
|
+
jobId: number;
|
|
39
|
+
statusCode: number;
|
|
40
|
+
contentLength: number;
|
|
41
|
+
headers: Record<string, string>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
interface RNFSDownloadProgressCallbackResult {
|
|
45
|
+
jobId: number;
|
|
46
|
+
contentLength: number;
|
|
47
|
+
bytesWritten: number;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
interface RNFSStatResult {
|
|
51
|
+
name: string;
|
|
52
|
+
path: string;
|
|
53
|
+
size: number;
|
|
54
|
+
mode: number;
|
|
55
|
+
ctime: number;
|
|
56
|
+
mtime: number;
|
|
57
|
+
isFile: () => boolean;
|
|
58
|
+
isDirectory: () => boolean;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
interface RNFSDownloadResult {
|
|
62
|
+
jobId: number;
|
|
63
|
+
statusCode: number;
|
|
64
|
+
bytesWritten: number;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
interface RNFSDownloadFileOptions {
|
|
68
|
+
fromUrl: string;
|
|
69
|
+
toFile: string;
|
|
70
|
+
headers?: Record<string, string>;
|
|
71
|
+
background?: boolean;
|
|
72
|
+
progressDivider?: number;
|
|
73
|
+
begin?: (res: RNFSDownloadBeginCallbackResult) => void;
|
|
74
|
+
progress?: (res: RNFSDownloadProgressCallbackResult) => void;
|
|
75
|
+
resumable?: () => void;
|
|
76
|
+
connectionTimeout?: number;
|
|
77
|
+
readTimeout?: number;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
interface RNFSModule {
|
|
81
|
+
DocumentDirectoryPath: string;
|
|
82
|
+
CachesDirectoryPath: string;
|
|
83
|
+
exists: (path: string) => Promise<boolean>;
|
|
84
|
+
mkdir: (path: string, options?: { NSURLIsExcludedFromBackupKey?: boolean }) => Promise<void>;
|
|
85
|
+
readDir: (path: string) => Promise<RNFSStatResult[]>;
|
|
86
|
+
readFile: (path: string, encoding?: string) => Promise<string>;
|
|
87
|
+
writeFile: (path: string, contents: string, encoding?: string) => Promise<void>;
|
|
88
|
+
moveFile: (source: string, dest: string) => Promise<void>;
|
|
89
|
+
copyFile: (source: string, dest: string) => Promise<void>;
|
|
90
|
+
unlink: (path: string) => Promise<void>;
|
|
91
|
+
stat: (path: string) => Promise<RNFSStatResult>;
|
|
92
|
+
getFSInfo: () => Promise<{ totalSpace: number; freeSpace: number }>;
|
|
93
|
+
downloadFile: (options: RNFSDownloadFileOptions) => { jobId: number; promise: Promise<RNFSDownloadResult> };
|
|
94
|
+
stopDownload: (jobId: number) => void;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Try to import react-native-fs
|
|
98
|
+
let RNFS: RNFSModule | null = null;
|
|
99
|
+
try {
|
|
100
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
101
|
+
RNFS = require('react-native-fs');
|
|
102
|
+
} catch {
|
|
103
|
+
logger.warning('react-native-fs not installed, file operations will be limited');
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Try to import react-native-zip-archive
|
|
107
|
+
let ZipArchive: {
|
|
108
|
+
unzip: (source: string, target: string) => Promise<string>;
|
|
109
|
+
unzipWithPassword: (source: string, target: string, password: string) => Promise<string>;
|
|
110
|
+
unzipAssets: (assetPath: string, target: string) => Promise<string>;
|
|
111
|
+
subscribe: (callback: (event: { progress: number; filePath: string }) => void) => { remove: () => void };
|
|
112
|
+
} | null = null;
|
|
113
|
+
try {
|
|
114
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
115
|
+
ZipArchive = require('react-native-zip-archive');
|
|
116
|
+
} catch {
|
|
117
|
+
logger.warning('react-native-zip-archive not installed, archive extraction will be limited');
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Constants matching Swift SDK path structure
|
|
121
|
+
const RUN_ANYWHERE_DIR = 'RunAnywhere';
|
|
122
|
+
const MODELS_DIR = 'Models';
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Download progress information
|
|
126
|
+
*/
|
|
127
|
+
export interface DownloadProgress {
|
|
128
|
+
bytesWritten: number;
|
|
129
|
+
contentLength: number;
|
|
130
|
+
progress: number;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Archive types supported for extraction
|
|
135
|
+
* Matches Swift SDK's ArchiveType enum
|
|
136
|
+
*/
|
|
137
|
+
export enum ArchiveType {
|
|
138
|
+
Zip = 'zip',
|
|
139
|
+
TarBz2 = 'tar.bz2',
|
|
140
|
+
TarGz = 'tar.gz',
|
|
141
|
+
TarXz = 'tar.xz',
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Describes the internal structure of an archive after extraction
|
|
146
|
+
* Matches Swift SDK's ArchiveStructure enum
|
|
147
|
+
*/
|
|
148
|
+
export enum ArchiveStructure {
|
|
149
|
+
SingleFileNested = 'singleFileNested',
|
|
150
|
+
DirectoryBased = 'directoryBased',
|
|
151
|
+
NestedDirectory = 'nestedDirectory',
|
|
152
|
+
Unknown = 'unknown',
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Model artifact type - describes how a model is packaged
|
|
157
|
+
* Matches Swift SDK's ModelArtifactType enum
|
|
158
|
+
*/
|
|
159
|
+
export type ModelArtifactType =
|
|
160
|
+
| { type: 'singleFile' }
|
|
161
|
+
| { type: 'archive'; archiveType: ArchiveType; structure: ArchiveStructure }
|
|
162
|
+
| { type: 'multiFile'; files: string[] }
|
|
163
|
+
| { type: 'custom'; strategyId: string }
|
|
164
|
+
| { type: 'builtIn' };
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Extraction result
|
|
168
|
+
*/
|
|
169
|
+
export interface ExtractionResult {
|
|
170
|
+
modelPath: string;
|
|
171
|
+
extractedSize: number;
|
|
172
|
+
fileCount: number;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Infer archive type from URL
|
|
177
|
+
*/
|
|
178
|
+
function inferArchiveType(url: string): ArchiveType | null {
|
|
179
|
+
const lowercased = url.toLowerCase();
|
|
180
|
+
if (lowercased.includes('.tar.bz2') || lowercased.includes('.tbz2')) {
|
|
181
|
+
return ArchiveType.TarBz2;
|
|
182
|
+
}
|
|
183
|
+
if (lowercased.includes('.tar.gz') || lowercased.includes('.tgz')) {
|
|
184
|
+
return ArchiveType.TarGz;
|
|
185
|
+
}
|
|
186
|
+
if (lowercased.includes('.tar.xz') || lowercased.includes('.txz')) {
|
|
187
|
+
return ArchiveType.TarXz;
|
|
188
|
+
}
|
|
189
|
+
if (lowercased.includes('.zip')) {
|
|
190
|
+
return ArchiveType.Zip;
|
|
191
|
+
}
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Infer framework from file name/extension
|
|
197
|
+
*/
|
|
198
|
+
function inferFramework(fileName: string): string {
|
|
199
|
+
const lower = fileName.toLowerCase();
|
|
200
|
+
if (lower.includes('.gguf') || lower.includes('.bin')) {
|
|
201
|
+
return 'LlamaCpp';
|
|
202
|
+
}
|
|
203
|
+
if (lower.includes('.onnx') || lower.includes('.tar') || lower.includes('.zip')) {
|
|
204
|
+
return 'ONNX';
|
|
205
|
+
}
|
|
206
|
+
return 'LlamaCpp'; // Default
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Extract base model ID (remove extension)
|
|
211
|
+
*/
|
|
212
|
+
function getBaseModelId(modelId: string): string {
|
|
213
|
+
return modelId
|
|
214
|
+
.replace('.gguf', '')
|
|
215
|
+
.replace('.onnx', '')
|
|
216
|
+
.replace('.tar.bz2', '')
|
|
217
|
+
.replace('.tar.gz', '')
|
|
218
|
+
.replace('.zip', '')
|
|
219
|
+
.replace('.bin', '');
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* File system service for model management
|
|
224
|
+
*/
|
|
225
|
+
export const FileSystem = {
|
|
226
|
+
/**
|
|
227
|
+
* Check if react-native-fs is available
|
|
228
|
+
*/
|
|
229
|
+
isAvailable(): boolean {
|
|
230
|
+
return RNFS !== null;
|
|
231
|
+
},
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Get the base documents directory
|
|
235
|
+
*/
|
|
236
|
+
getDocumentsDirectory(): string {
|
|
237
|
+
if (!RNFS) {
|
|
238
|
+
throw new Error('react-native-fs not installed');
|
|
239
|
+
}
|
|
240
|
+
return Platform.OS === 'android'
|
|
241
|
+
? RNFS.DocumentDirectoryPath
|
|
242
|
+
: RNFS.DocumentDirectoryPath;
|
|
243
|
+
},
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Get the RunAnywhere base directory
|
|
247
|
+
* Returns: Documents/RunAnywhere/
|
|
248
|
+
*/
|
|
249
|
+
getRunAnywhereDirectory(): string {
|
|
250
|
+
return `${this.getDocumentsDirectory()}/${RUN_ANYWHERE_DIR}`;
|
|
251
|
+
},
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Get the models directory
|
|
255
|
+
* Returns: Documents/RunAnywhere/Models/
|
|
256
|
+
*/
|
|
257
|
+
getModelsDirectory(): string {
|
|
258
|
+
return `${this.getRunAnywhereDirectory()}/${MODELS_DIR}`;
|
|
259
|
+
},
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Get framework directory
|
|
263
|
+
* Returns: Documents/RunAnywhere/Models/{framework}/
|
|
264
|
+
*/
|
|
265
|
+
getFrameworkDirectory(framework: string): string {
|
|
266
|
+
return `${this.getModelsDirectory()}/${framework}`;
|
|
267
|
+
},
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Get model folder
|
|
271
|
+
* Returns: Documents/RunAnywhere/Models/{framework}/{modelId}/
|
|
272
|
+
*/
|
|
273
|
+
getModelFolder(modelId: string, framework?: string): string {
|
|
274
|
+
const fw = framework || inferFramework(modelId);
|
|
275
|
+
const baseId = getBaseModelId(modelId);
|
|
276
|
+
return `${this.getFrameworkDirectory(fw)}/${baseId}`;
|
|
277
|
+
},
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Get model file path
|
|
281
|
+
* For LlamaCpp: Documents/RunAnywhere/Models/LlamaCpp/{modelId}/{modelId}.gguf
|
|
282
|
+
* For ONNX: Documents/RunAnywhere/Models/ONNX/{modelId}/ (folder, checking for nested dirs)
|
|
283
|
+
*/
|
|
284
|
+
async getModelPath(modelId: string, framework?: string): Promise<string> {
|
|
285
|
+
const fw = framework || inferFramework(modelId);
|
|
286
|
+
const folder = this.getModelFolder(modelId, fw);
|
|
287
|
+
const baseId = getBaseModelId(modelId);
|
|
288
|
+
|
|
289
|
+
if (fw === 'LlamaCpp') {
|
|
290
|
+
// Single file model
|
|
291
|
+
const ext = modelId.includes('.gguf')
|
|
292
|
+
? '.gguf'
|
|
293
|
+
: modelId.includes('.bin')
|
|
294
|
+
? '.bin'
|
|
295
|
+
: '.gguf';
|
|
296
|
+
return `${folder}/${baseId}${ext}`;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// For ONNX, check if the model is in a nested directory structure
|
|
300
|
+
if (RNFS) {
|
|
301
|
+
try {
|
|
302
|
+
const exists = await RNFS.exists(folder);
|
|
303
|
+
if (exists) {
|
|
304
|
+
// Find the actual model path (handles nested directory structures)
|
|
305
|
+
const modelPath = await this.findModelPathAfterExtraction(folder);
|
|
306
|
+
return modelPath;
|
|
307
|
+
}
|
|
308
|
+
} catch {
|
|
309
|
+
// Fall through to return the default folder
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// Directory-based model (ONNX)
|
|
314
|
+
return folder;
|
|
315
|
+
},
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Check if a model exists
|
|
319
|
+
* For LlamaCpp: checks if the .gguf file exists
|
|
320
|
+
* For ONNX: checks if the folder has .onnx files (extracted archive)
|
|
321
|
+
*/
|
|
322
|
+
async modelExists(modelId: string, framework?: string): Promise<boolean> {
|
|
323
|
+
if (!RNFS) return false;
|
|
324
|
+
|
|
325
|
+
const fw = framework || inferFramework(modelId);
|
|
326
|
+
const folder = this.getModelFolder(modelId, fw);
|
|
327
|
+
|
|
328
|
+
try {
|
|
329
|
+
const exists = await RNFS.exists(folder);
|
|
330
|
+
if (!exists) return false;
|
|
331
|
+
|
|
332
|
+
// Check if folder has contents
|
|
333
|
+
const files = await RNFS.readDir(folder);
|
|
334
|
+
if (files.length === 0) return false;
|
|
335
|
+
|
|
336
|
+
if (fw === 'ONNX') {
|
|
337
|
+
// For ONNX, we need to check if there are actual model files (not just an archive)
|
|
338
|
+
// ONNX models should have .onnx files after extraction
|
|
339
|
+
const hasOnnxFiles = await this.hasModelFiles(folder);
|
|
340
|
+
return hasOnnxFiles;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
return true;
|
|
344
|
+
} catch {
|
|
345
|
+
return false;
|
|
346
|
+
}
|
|
347
|
+
},
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Recursively check if a folder contains model files
|
|
351
|
+
*/
|
|
352
|
+
async hasModelFiles(folder: string): Promise<boolean> {
|
|
353
|
+
if (!RNFS) return false;
|
|
354
|
+
|
|
355
|
+
try {
|
|
356
|
+
const contents = await RNFS.readDir(folder);
|
|
357
|
+
|
|
358
|
+
for (const item of contents) {
|
|
359
|
+
if (item.isFile()) {
|
|
360
|
+
const name = item.name.toLowerCase();
|
|
361
|
+
// Check for actual model files, not archive files
|
|
362
|
+
if (name.endsWith('.onnx') || name.endsWith('.bin') || name.endsWith('.txt')) {
|
|
363
|
+
return true;
|
|
364
|
+
}
|
|
365
|
+
} else if (item.isDirectory()) {
|
|
366
|
+
// Check nested directories
|
|
367
|
+
const hasFiles = await this.hasModelFiles(item.path);
|
|
368
|
+
if (hasFiles) return true;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
return false;
|
|
373
|
+
} catch {
|
|
374
|
+
return false;
|
|
375
|
+
}
|
|
376
|
+
},
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Create directory if it doesn't exist
|
|
380
|
+
*/
|
|
381
|
+
async ensureDirectory(path: string): Promise<void> {
|
|
382
|
+
if (!RNFS) return;
|
|
383
|
+
|
|
384
|
+
try {
|
|
385
|
+
const exists = await RNFS.exists(path);
|
|
386
|
+
if (!exists) {
|
|
387
|
+
await RNFS.mkdir(path);
|
|
388
|
+
}
|
|
389
|
+
} catch (error) {
|
|
390
|
+
logger.error(`Failed to create directory: ${path}`, { error });
|
|
391
|
+
}
|
|
392
|
+
},
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* Download a model file
|
|
396
|
+
*/
|
|
397
|
+
async downloadModel(
|
|
398
|
+
modelId: string,
|
|
399
|
+
url: string,
|
|
400
|
+
onProgress?: (progress: DownloadProgress) => void,
|
|
401
|
+
framework?: string
|
|
402
|
+
): Promise<string> {
|
|
403
|
+
if (!RNFS) {
|
|
404
|
+
throw new Error('react-native-fs not installed');
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
const fw = framework || inferFramework(modelId);
|
|
408
|
+
const folder = this.getModelFolder(modelId, fw);
|
|
409
|
+
const baseId = getBaseModelId(modelId);
|
|
410
|
+
|
|
411
|
+
// Ensure directory structure exists
|
|
412
|
+
await this.ensureDirectory(this.getRunAnywhereDirectory());
|
|
413
|
+
await this.ensureDirectory(this.getModelsDirectory());
|
|
414
|
+
await this.ensureDirectory(this.getFrameworkDirectory(fw));
|
|
415
|
+
await this.ensureDirectory(folder);
|
|
416
|
+
|
|
417
|
+
// Determine destination path
|
|
418
|
+
let destPath: string;
|
|
419
|
+
if (fw === 'LlamaCpp') {
|
|
420
|
+
const ext =
|
|
421
|
+
modelId.includes('.gguf') || url.includes('.gguf')
|
|
422
|
+
? '.gguf'
|
|
423
|
+
: modelId.includes('.bin') || url.includes('.bin')
|
|
424
|
+
? '.bin'
|
|
425
|
+
: '.gguf';
|
|
426
|
+
destPath = `${folder}/${baseId}${ext}`;
|
|
427
|
+
} else {
|
|
428
|
+
// For archives, download to temp first
|
|
429
|
+
const tempName = `${baseId}_${Date.now()}.tmp`;
|
|
430
|
+
destPath = `${RNFS.CachesDirectoryPath}/${tempName}`;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
logger.info(`Downloading model: ${modelId}`);
|
|
434
|
+
logger.debug(`URL: ${url}`);
|
|
435
|
+
logger.debug(`Destination: ${destPath}`);
|
|
436
|
+
|
|
437
|
+
// Check if already exists
|
|
438
|
+
const exists = await RNFS.exists(destPath);
|
|
439
|
+
if (exists && fw === 'LlamaCpp') {
|
|
440
|
+
logger.info(`Model already exists: ${destPath}`);
|
|
441
|
+
return destPath;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
// Download with progress
|
|
445
|
+
const downloadResult = RNFS.downloadFile({
|
|
446
|
+
fromUrl: url,
|
|
447
|
+
toFile: destPath,
|
|
448
|
+
background: true,
|
|
449
|
+
progressDivider: 1,
|
|
450
|
+
begin: (res) => {
|
|
451
|
+
logger.info(
|
|
452
|
+
`Download started: ${res.contentLength} bytes, status: ${res.statusCode}`
|
|
453
|
+
);
|
|
454
|
+
},
|
|
455
|
+
progress: (res) => {
|
|
456
|
+
const progress = res.contentLength > 0
|
|
457
|
+
? res.bytesWritten / res.contentLength
|
|
458
|
+
: 0;
|
|
459
|
+
|
|
460
|
+
if (onProgress) {
|
|
461
|
+
onProgress({
|
|
462
|
+
bytesWritten: res.bytesWritten,
|
|
463
|
+
contentLength: res.contentLength,
|
|
464
|
+
progress,
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
},
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
const result = await downloadResult.promise;
|
|
471
|
+
|
|
472
|
+
if (result.statusCode !== 200) {
|
|
473
|
+
throw new Error(`Download failed with status: ${result.statusCode}`);
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
logger.info(`Download completed: ${result.bytesWritten} bytes`);
|
|
477
|
+
|
|
478
|
+
// For ONNX archives, extract to final location
|
|
479
|
+
const archiveType = inferArchiveType(url);
|
|
480
|
+
if (fw === 'ONNX' && archiveType !== null) {
|
|
481
|
+
logger.info(`Extracting ${archiveType} archive...`);
|
|
482
|
+
|
|
483
|
+
try {
|
|
484
|
+
const extractionResult = await this.extractArchive(destPath, folder, archiveType);
|
|
485
|
+
logger.info(`Extraction completed: ${extractionResult.fileCount} files, ${extractionResult.extractedSize} bytes`);
|
|
486
|
+
|
|
487
|
+
// Clean up the temporary archive file
|
|
488
|
+
await RNFS.unlink(destPath);
|
|
489
|
+
|
|
490
|
+
// Return the extracted folder path
|
|
491
|
+
destPath = extractionResult.modelPath;
|
|
492
|
+
} catch (extractError) {
|
|
493
|
+
logger.error(`Archive extraction failed: ${extractError}`);
|
|
494
|
+
// Clean up temp file on failure
|
|
495
|
+
try {
|
|
496
|
+
await RNFS.unlink(destPath);
|
|
497
|
+
} catch {
|
|
498
|
+
// Ignore cleanup errors
|
|
499
|
+
}
|
|
500
|
+
throw new Error(`Archive extraction failed: ${extractError}`);
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
return destPath;
|
|
505
|
+
},
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* Extract an archive to a destination folder
|
|
509
|
+
* Uses native extraction via the core module (iOS: ArchiveUtility, Android: native extraction)
|
|
510
|
+
*/
|
|
511
|
+
async extractArchive(
|
|
512
|
+
archivePath: string,
|
|
513
|
+
destinationFolder: string,
|
|
514
|
+
archiveType: ArchiveType,
|
|
515
|
+
onProgress?: (progress: number) => void
|
|
516
|
+
): Promise<ExtractionResult> {
|
|
517
|
+
if (!RNFS) {
|
|
518
|
+
throw new Error('react-native-fs not installed');
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
logger.info(`Extracting archive: ${archivePath}`);
|
|
522
|
+
logger.info(`Archive type: ${archiveType}`);
|
|
523
|
+
logger.info(`Destination: ${destinationFolder}`);
|
|
524
|
+
|
|
525
|
+
// Ensure destination exists
|
|
526
|
+
await this.ensureDirectory(destinationFolder);
|
|
527
|
+
|
|
528
|
+
// Try native extraction first (supports tar.gz, tar.bz2, zip)
|
|
529
|
+
try {
|
|
530
|
+
const native = getNativeModule();
|
|
531
|
+
if (!native) {
|
|
532
|
+
throw new Error('Native module not available');
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
logger.info('Using native archive extraction...');
|
|
536
|
+
const success = await native.extractArchive(archivePath, destinationFolder);
|
|
537
|
+
|
|
538
|
+
if (!success) {
|
|
539
|
+
throw new Error('Native extraction returned false');
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
logger.info('Native extraction completed successfully');
|
|
543
|
+
} catch (nativeError) {
|
|
544
|
+
logger.warning(`Native extraction failed: ${nativeError}, trying fallback...`);
|
|
545
|
+
|
|
546
|
+
// Fallback to react-native-zip-archive for ZIP files only
|
|
547
|
+
if (archiveType === ArchiveType.Zip && ZipArchive) {
|
|
548
|
+
logger.info('Falling back to react-native-zip-archive for ZIP...');
|
|
549
|
+
|
|
550
|
+
let subscription: { remove: () => void } | null = null;
|
|
551
|
+
if (onProgress) {
|
|
552
|
+
subscription = ZipArchive.subscribe(({ progress }) => {
|
|
553
|
+
onProgress(progress);
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
try {
|
|
558
|
+
await ZipArchive.unzip(archivePath, destinationFolder);
|
|
559
|
+
} finally {
|
|
560
|
+
if (subscription) {
|
|
561
|
+
subscription.remove();
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
} else if (archiveType === ArchiveType.TarGz || archiveType === ArchiveType.TarBz2) {
|
|
565
|
+
// No fallback for tar archives - native is required
|
|
566
|
+
throw new Error(
|
|
567
|
+
`Archive extraction failed for ${archiveType}. Native extraction is required for tar archives. Error: ${nativeError}`
|
|
568
|
+
);
|
|
569
|
+
} else {
|
|
570
|
+
throw new Error(`Archive extraction failed: ${nativeError}`);
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
// After extraction, find the actual model path
|
|
575
|
+
// ONNX models are typically nested in a directory with the same name
|
|
576
|
+
const modelPath = await this.findModelPathAfterExtraction(destinationFolder);
|
|
577
|
+
|
|
578
|
+
// Calculate extraction stats
|
|
579
|
+
const stats = await this.calculateExtractionStats(destinationFolder);
|
|
580
|
+
|
|
581
|
+
return {
|
|
582
|
+
modelPath,
|
|
583
|
+
extractedSize: stats.totalSize,
|
|
584
|
+
fileCount: stats.fileCount,
|
|
585
|
+
};
|
|
586
|
+
},
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* Find the actual model path after extraction
|
|
590
|
+
* Handles nested directory structures common in ONNX archives
|
|
591
|
+
*/
|
|
592
|
+
async findModelPathAfterExtraction(extractedFolder: string): Promise<string> {
|
|
593
|
+
if (!RNFS) {
|
|
594
|
+
return extractedFolder;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
try {
|
|
598
|
+
const contents = await RNFS.readDir(extractedFolder);
|
|
599
|
+
|
|
600
|
+
// If there's exactly one directory and no files, it might be a nested structure
|
|
601
|
+
const directories = contents.filter(item => item.isDirectory());
|
|
602
|
+
const files = contents.filter(item => item.isFile());
|
|
603
|
+
|
|
604
|
+
if (directories.length === 1 && files.length === 0) {
|
|
605
|
+
// Nested directory - the actual model is inside
|
|
606
|
+
const nestedDir = directories[0];
|
|
607
|
+
logger.info(`Found nested directory structure: ${nestedDir.name}`);
|
|
608
|
+
return nestedDir.path;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
// Otherwise, the extracted folder contains the model directly
|
|
612
|
+
return extractedFolder;
|
|
613
|
+
} catch (error) {
|
|
614
|
+
logger.error(`Error finding model path: ${error}`);
|
|
615
|
+
return extractedFolder;
|
|
616
|
+
}
|
|
617
|
+
},
|
|
618
|
+
|
|
619
|
+
/**
|
|
620
|
+
* Calculate extraction statistics
|
|
621
|
+
*/
|
|
622
|
+
async calculateExtractionStats(folder: string): Promise<{ totalSize: number; fileCount: number }> {
|
|
623
|
+
if (!RNFS) {
|
|
624
|
+
return { totalSize: 0, fileCount: 0 };
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
let totalSize = 0;
|
|
628
|
+
let fileCount = 0;
|
|
629
|
+
|
|
630
|
+
const processDir = async (dir: string) => {
|
|
631
|
+
try {
|
|
632
|
+
const contents = await RNFS!.readDir(dir);
|
|
633
|
+
for (const item of contents) {
|
|
634
|
+
if (item.isFile()) {
|
|
635
|
+
totalSize += item.size;
|
|
636
|
+
fileCount++;
|
|
637
|
+
} else if (item.isDirectory()) {
|
|
638
|
+
await processDir(item.path);
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
} catch {
|
|
642
|
+
// Ignore errors
|
|
643
|
+
}
|
|
644
|
+
};
|
|
645
|
+
|
|
646
|
+
await processDir(folder);
|
|
647
|
+
return { totalSize, fileCount };
|
|
648
|
+
},
|
|
649
|
+
|
|
650
|
+
/**
|
|
651
|
+
* Delete a model
|
|
652
|
+
*/
|
|
653
|
+
async deleteModel(modelId: string, framework?: string): Promise<boolean> {
|
|
654
|
+
if (!RNFS) return false;
|
|
655
|
+
|
|
656
|
+
const fw = framework || inferFramework(modelId);
|
|
657
|
+
const folder = this.getModelFolder(modelId, fw);
|
|
658
|
+
|
|
659
|
+
try {
|
|
660
|
+
const exists = await RNFS.exists(folder);
|
|
661
|
+
if (exists) {
|
|
662
|
+
await RNFS.unlink(folder);
|
|
663
|
+
return true;
|
|
664
|
+
}
|
|
665
|
+
return false;
|
|
666
|
+
} catch (error) {
|
|
667
|
+
logger.error(`Failed to delete model: ${modelId}`, { error });
|
|
668
|
+
return false;
|
|
669
|
+
}
|
|
670
|
+
},
|
|
671
|
+
|
|
672
|
+
/**
|
|
673
|
+
* Get available disk space in bytes
|
|
674
|
+
*/
|
|
675
|
+
async getAvailableDiskSpace(): Promise<number> {
|
|
676
|
+
if (!RNFS) return 0;
|
|
677
|
+
|
|
678
|
+
try {
|
|
679
|
+
const info = await RNFS.getFSInfo();
|
|
680
|
+
return info.freeSpace;
|
|
681
|
+
} catch {
|
|
682
|
+
return 0;
|
|
683
|
+
}
|
|
684
|
+
},
|
|
685
|
+
|
|
686
|
+
/**
|
|
687
|
+
* Get total disk space in bytes
|
|
688
|
+
*/
|
|
689
|
+
async getTotalDiskSpace(): Promise<number> {
|
|
690
|
+
if (!RNFS) return 0;
|
|
691
|
+
|
|
692
|
+
try {
|
|
693
|
+
const info = await RNFS.getFSInfo();
|
|
694
|
+
return info.totalSpace;
|
|
695
|
+
} catch {
|
|
696
|
+
return 0;
|
|
697
|
+
}
|
|
698
|
+
},
|
|
699
|
+
|
|
700
|
+
/**
|
|
701
|
+
* Read a file as string
|
|
702
|
+
*/
|
|
703
|
+
async readFile(path: string): Promise<string> {
|
|
704
|
+
if (!RNFS) {
|
|
705
|
+
throw new Error('react-native-fs not installed');
|
|
706
|
+
}
|
|
707
|
+
return RNFS.readFile(path, 'utf8');
|
|
708
|
+
},
|
|
709
|
+
|
|
710
|
+
/**
|
|
711
|
+
* Write a string to a file
|
|
712
|
+
*/
|
|
713
|
+
async writeFile(path: string, content: string): Promise<void> {
|
|
714
|
+
if (!RNFS) {
|
|
715
|
+
throw new Error('react-native-fs not installed');
|
|
716
|
+
}
|
|
717
|
+
await RNFS.writeFile(path, content, 'utf8');
|
|
718
|
+
},
|
|
719
|
+
|
|
720
|
+
/**
|
|
721
|
+
* Check if a file exists
|
|
722
|
+
*/
|
|
723
|
+
async fileExists(path: string): Promise<boolean> {
|
|
724
|
+
if (!RNFS) return false;
|
|
725
|
+
return RNFS.exists(path);
|
|
726
|
+
},
|
|
727
|
+
|
|
728
|
+
/**
|
|
729
|
+
* Check if a directory exists
|
|
730
|
+
*/
|
|
731
|
+
async directoryExists(path: string): Promise<boolean> {
|
|
732
|
+
if (!RNFS) return false;
|
|
733
|
+
try {
|
|
734
|
+
const exists = await RNFS.exists(path);
|
|
735
|
+
if (!exists) return false;
|
|
736
|
+
const stat = await RNFS.stat(path);
|
|
737
|
+
return stat.isDirectory();
|
|
738
|
+
} catch {
|
|
739
|
+
return false;
|
|
740
|
+
}
|
|
741
|
+
},
|
|
742
|
+
|
|
743
|
+
/**
|
|
744
|
+
* Get the size of a directory in bytes (recursive)
|
|
745
|
+
*/
|
|
746
|
+
async getDirectorySize(dirPath: string): Promise<number> {
|
|
747
|
+
if (!RNFS) return 0;
|
|
748
|
+
|
|
749
|
+
try {
|
|
750
|
+
const exists = await RNFS.exists(dirPath);
|
|
751
|
+
if (!exists) return 0;
|
|
752
|
+
|
|
753
|
+
let totalSize = 0;
|
|
754
|
+
const contents = await RNFS.readDir(dirPath);
|
|
755
|
+
|
|
756
|
+
for (const item of contents) {
|
|
757
|
+
if (item.isDirectory()) {
|
|
758
|
+
totalSize += await this.getDirectorySize(item.path);
|
|
759
|
+
} else {
|
|
760
|
+
totalSize += item.size || 0;
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
return totalSize;
|
|
765
|
+
} catch {
|
|
766
|
+
return 0;
|
|
767
|
+
}
|
|
768
|
+
},
|
|
769
|
+
|
|
770
|
+
/**
|
|
771
|
+
* Get the cache directory path
|
|
772
|
+
*/
|
|
773
|
+
getCacheDirectory(): string {
|
|
774
|
+
if (!RNFS) return '';
|
|
775
|
+
return RNFS.CachesDirectoryPath;
|
|
776
|
+
},
|
|
777
|
+
|
|
778
|
+
/**
|
|
779
|
+
* List contents of a directory
|
|
780
|
+
*/
|
|
781
|
+
async listDirectory(dirPath: string): Promise<string[]> {
|
|
782
|
+
if (!RNFS) return [];
|
|
783
|
+
|
|
784
|
+
try {
|
|
785
|
+
const exists = await RNFS.exists(dirPath);
|
|
786
|
+
if (!exists) return [];
|
|
787
|
+
|
|
788
|
+
const contents = await RNFS.readDir(dirPath);
|
|
789
|
+
return contents.map((item) => item.name);
|
|
790
|
+
} catch {
|
|
791
|
+
return [];
|
|
792
|
+
}
|
|
793
|
+
},
|
|
794
|
+
|
|
795
|
+
/**
|
|
796
|
+
* Delete a file
|
|
797
|
+
*/
|
|
798
|
+
async deleteFile(path: string): Promise<boolean> {
|
|
799
|
+
if (!RNFS) return false;
|
|
800
|
+
|
|
801
|
+
try {
|
|
802
|
+
await RNFS.unlink(path);
|
|
803
|
+
return true;
|
|
804
|
+
} catch {
|
|
805
|
+
return false;
|
|
806
|
+
}
|
|
807
|
+
},
|
|
808
|
+
};
|
|
809
|
+
|
|
810
|
+
export default FileSystem;
|