@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,320 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RunAnywhere+TextGeneration.ts
|
|
3
|
+
*
|
|
4
|
+
* Text generation (LLM) extension for RunAnywhere SDK.
|
|
5
|
+
* Uses backend-agnostic rac_llm_component_* C++ APIs via the core native module.
|
|
6
|
+
* The actual backend (LlamaCPP, etc.) must be registered by installing
|
|
7
|
+
* and importing the appropriate backend package (e.g., @runanywhere/llamacpp).
|
|
8
|
+
*
|
|
9
|
+
* Matches iOS: RunAnywhere+TextGeneration.swift
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { EventBus } from '../Events';
|
|
13
|
+
import {
|
|
14
|
+
requireNativeModule,
|
|
15
|
+
isNativeModuleAvailable,
|
|
16
|
+
} from '../../native';
|
|
17
|
+
import type { GenerationOptions, GenerationResult } from '../../types';
|
|
18
|
+
import { ExecutionTarget, HardwareAcceleration } from '../../types';
|
|
19
|
+
import { SDKLogger } from '../../Foundation/Logging/Logger/SDKLogger';
|
|
20
|
+
import type {
|
|
21
|
+
LLMStreamingResult,
|
|
22
|
+
LLMGenerationResult,
|
|
23
|
+
} from '../../types/LLMTypes';
|
|
24
|
+
|
|
25
|
+
const logger = new SDKLogger('RunAnywhere.TextGeneration');
|
|
26
|
+
|
|
27
|
+
// ============================================================================
|
|
28
|
+
// Text Generation (LLM) Extension - Backend Agnostic
|
|
29
|
+
// ============================================================================
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Load an LLM model by ID or path
|
|
33
|
+
*
|
|
34
|
+
* Matches iOS: `RunAnywhere.loadModel(_:)`
|
|
35
|
+
* @throws Error if no LLM backend is registered
|
|
36
|
+
*/
|
|
37
|
+
export async function loadModel(
|
|
38
|
+
modelPathOrId: string,
|
|
39
|
+
config?: Record<string, unknown>
|
|
40
|
+
): Promise<boolean> {
|
|
41
|
+
if (!isNativeModuleAvailable()) {
|
|
42
|
+
logger.warning('Native module not available for loadModel');
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
const native = requireNativeModule();
|
|
46
|
+
return native.loadTextModel(
|
|
47
|
+
modelPathOrId,
|
|
48
|
+
config ? JSON.stringify(config) : undefined
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Check if an LLM model is loaded
|
|
54
|
+
* Matches iOS: `RunAnywhere.isModelLoaded`
|
|
55
|
+
*/
|
|
56
|
+
export async function isModelLoaded(): Promise<boolean> {
|
|
57
|
+
if (!isNativeModuleAvailable()) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
const native = requireNativeModule();
|
|
61
|
+
return native.isTextModelLoaded();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Unload the currently loaded LLM model
|
|
66
|
+
* Matches iOS: `RunAnywhere.unloadModel()`
|
|
67
|
+
*/
|
|
68
|
+
export async function unloadModel(): Promise<boolean> {
|
|
69
|
+
if (!isNativeModuleAvailable()) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
const native = requireNativeModule();
|
|
73
|
+
return native.unloadTextModel();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Simple chat - returns just the text response
|
|
78
|
+
* Matches Swift SDK: RunAnywhere.chat(_:)
|
|
79
|
+
*/
|
|
80
|
+
export async function chat(prompt: string): Promise<string> {
|
|
81
|
+
const result = await generate(prompt);
|
|
82
|
+
return result.text;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Text generation with options and full metrics
|
|
87
|
+
* Matches Swift SDK: RunAnywhere.generate(_:options:)
|
|
88
|
+
*/
|
|
89
|
+
export async function generate(
|
|
90
|
+
prompt: string,
|
|
91
|
+
options?: GenerationOptions
|
|
92
|
+
): Promise<GenerationResult> {
|
|
93
|
+
if (!isNativeModuleAvailable()) {
|
|
94
|
+
throw new Error('Native module not available');
|
|
95
|
+
}
|
|
96
|
+
const native = requireNativeModule();
|
|
97
|
+
|
|
98
|
+
const optionsJson = JSON.stringify({
|
|
99
|
+
max_tokens: options?.maxTokens ?? 1000,
|
|
100
|
+
temperature: options?.temperature ?? 0.7,
|
|
101
|
+
system_prompt: options?.systemPrompt ?? null,
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const resultJson = await native.generate(prompt, optionsJson);
|
|
105
|
+
|
|
106
|
+
try {
|
|
107
|
+
const result = JSON.parse(resultJson);
|
|
108
|
+
return {
|
|
109
|
+
text: result.text ?? '',
|
|
110
|
+
thinkingContent: result.thinkingContent,
|
|
111
|
+
tokensUsed: result.tokensUsed ?? 0,
|
|
112
|
+
modelUsed: result.modelUsed ?? 'unknown',
|
|
113
|
+
latencyMs: result.latencyMs ?? 0,
|
|
114
|
+
executionTarget: result.executionTarget ?? 0,
|
|
115
|
+
savedAmount: result.savedAmount ?? 0,
|
|
116
|
+
framework: result.framework,
|
|
117
|
+
hardwareUsed: result.hardwareUsed ?? 0,
|
|
118
|
+
memoryUsed: result.memoryUsed ?? 0,
|
|
119
|
+
performanceMetrics: {
|
|
120
|
+
timeToFirstTokenMs: result.performanceMetrics?.timeToFirstTokenMs,
|
|
121
|
+
tokensPerSecond: result.performanceMetrics?.tokensPerSecond,
|
|
122
|
+
inferenceTimeMs:
|
|
123
|
+
result.performanceMetrics?.inferenceTimeMs ?? result.latencyMs ?? 0,
|
|
124
|
+
},
|
|
125
|
+
thinkingTokens: result.thinkingTokens,
|
|
126
|
+
responseTokens: result.responseTokens ?? result.tokensUsed ?? 0,
|
|
127
|
+
};
|
|
128
|
+
} catch {
|
|
129
|
+
if (resultJson.includes('error')) {
|
|
130
|
+
throw new Error(resultJson);
|
|
131
|
+
}
|
|
132
|
+
return {
|
|
133
|
+
text: resultJson,
|
|
134
|
+
tokensUsed: 0,
|
|
135
|
+
modelUsed: 'unknown',
|
|
136
|
+
latencyMs: 0,
|
|
137
|
+
executionTarget: ExecutionTarget.OnDevice,
|
|
138
|
+
savedAmount: 0,
|
|
139
|
+
hardwareUsed: HardwareAcceleration.CPU,
|
|
140
|
+
memoryUsed: 0,
|
|
141
|
+
performanceMetrics: {
|
|
142
|
+
inferenceTimeMs: 0,
|
|
143
|
+
},
|
|
144
|
+
responseTokens: 0,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Streaming text generation with async iterator
|
|
151
|
+
*
|
|
152
|
+
* Returns a LLMStreamingResult containing:
|
|
153
|
+
* - stream: AsyncIterable<string> for consuming tokens
|
|
154
|
+
* - result: Promise<LLMGenerationResult> for final metrics
|
|
155
|
+
* - cancel: Function to cancel generation
|
|
156
|
+
*
|
|
157
|
+
* Matches Swift SDK: RunAnywhere.generateStream(_:options:)
|
|
158
|
+
*
|
|
159
|
+
* Example usage:
|
|
160
|
+
* ```typescript
|
|
161
|
+
* const streaming = await generateStream(prompt);
|
|
162
|
+
*
|
|
163
|
+
* // Display tokens in real-time
|
|
164
|
+
* for await (const token of streaming.stream) {
|
|
165
|
+
* console.log(token);
|
|
166
|
+
* }
|
|
167
|
+
*
|
|
168
|
+
* // Get complete analytics after streaming finishes
|
|
169
|
+
* const metrics = await streaming.result;
|
|
170
|
+
* console.log(`Speed: ${metrics.tokensPerSecond} tok/s`);
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
export async function generateStream(
|
|
174
|
+
prompt: string,
|
|
175
|
+
options?: GenerationOptions
|
|
176
|
+
): Promise<LLMStreamingResult> {
|
|
177
|
+
if (!isNativeModuleAvailable()) {
|
|
178
|
+
throw new Error('Native module not available');
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const native = requireNativeModule();
|
|
182
|
+
const startTime = Date.now();
|
|
183
|
+
let firstTokenTime: number | null = null;
|
|
184
|
+
let cancelled = false;
|
|
185
|
+
let fullText = '';
|
|
186
|
+
let tokenCount = 0;
|
|
187
|
+
let resolveResult: ((result: LLMGenerationResult) => void) | null = null;
|
|
188
|
+
let rejectResult: ((error: Error) => void) | null = null;
|
|
189
|
+
|
|
190
|
+
const optionsJson = JSON.stringify({
|
|
191
|
+
max_tokens: options?.maxTokens ?? 1000,
|
|
192
|
+
temperature: options?.temperature ?? 0.7,
|
|
193
|
+
system_prompt: options?.systemPrompt ?? null,
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
// Create the result promise
|
|
197
|
+
const resultPromise = new Promise<LLMGenerationResult>((resolve, reject) => {
|
|
198
|
+
resolveResult = resolve;
|
|
199
|
+
rejectResult = reject;
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
// Create async generator for tokens
|
|
203
|
+
async function* tokenGenerator(): AsyncGenerator<string> {
|
|
204
|
+
const tokenQueue: string[] = [];
|
|
205
|
+
let resolver: ((value: IteratorResult<string>) => void) | null = null;
|
|
206
|
+
let done = false;
|
|
207
|
+
let error: Error | null = null;
|
|
208
|
+
|
|
209
|
+
// Start streaming
|
|
210
|
+
native.generateStream(
|
|
211
|
+
prompt,
|
|
212
|
+
optionsJson,
|
|
213
|
+
(token: string, isComplete: boolean) => {
|
|
214
|
+
if (cancelled) return;
|
|
215
|
+
|
|
216
|
+
if (!isComplete && token) {
|
|
217
|
+
// Track first token time
|
|
218
|
+
if (firstTokenTime === null) {
|
|
219
|
+
firstTokenTime = Date.now();
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
fullText += token;
|
|
223
|
+
tokenCount++;
|
|
224
|
+
|
|
225
|
+
if (resolver) {
|
|
226
|
+
resolver({ value: token, done: false });
|
|
227
|
+
resolver = null;
|
|
228
|
+
} else {
|
|
229
|
+
tokenQueue.push(token);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (isComplete) {
|
|
234
|
+
done = true;
|
|
235
|
+
|
|
236
|
+
// Build final result
|
|
237
|
+
const endTime = Date.now();
|
|
238
|
+
const latencyMs = endTime - startTime;
|
|
239
|
+
const timeToFirstTokenMs = firstTokenTime ? firstTokenTime - startTime : undefined;
|
|
240
|
+
const tokensPerSecond = latencyMs > 0 ? (tokenCount / latencyMs) * 1000 : 0;
|
|
241
|
+
|
|
242
|
+
const finalResult: LLMGenerationResult = {
|
|
243
|
+
text: fullText,
|
|
244
|
+
thinkingContent: undefined,
|
|
245
|
+
inputTokens: Math.ceil(prompt.length / 4),
|
|
246
|
+
tokensUsed: tokenCount,
|
|
247
|
+
modelUsed: 'unknown',
|
|
248
|
+
latencyMs,
|
|
249
|
+
framework: 'unknown', // Backend-agnostic
|
|
250
|
+
tokensPerSecond,
|
|
251
|
+
timeToFirstTokenMs,
|
|
252
|
+
thinkingTokens: 0,
|
|
253
|
+
responseTokens: tokenCount,
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
if (resolveResult) {
|
|
257
|
+
resolveResult(finalResult);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if (resolver) {
|
|
261
|
+
resolver({ value: undefined as unknown as string, done: true });
|
|
262
|
+
resolver = null;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
EventBus.publish('Generation', { type: 'completed' });
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
).catch((err: Error) => {
|
|
269
|
+
error = err;
|
|
270
|
+
done = true;
|
|
271
|
+
if (rejectResult) {
|
|
272
|
+
rejectResult(err);
|
|
273
|
+
}
|
|
274
|
+
if (resolver) {
|
|
275
|
+
resolver({ value: undefined as unknown as string, done: true });
|
|
276
|
+
}
|
|
277
|
+
EventBus.publish('Generation', { type: 'failed', error: err.message });
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
// Yield tokens
|
|
281
|
+
while (!done || tokenQueue.length > 0) {
|
|
282
|
+
if (tokenQueue.length > 0) {
|
|
283
|
+
yield tokenQueue.shift()!;
|
|
284
|
+
} else if (!done) {
|
|
285
|
+
const result = await new Promise<IteratorResult<string>>((resolve) => {
|
|
286
|
+
resolver = resolve;
|
|
287
|
+
});
|
|
288
|
+
if (result.done) break;
|
|
289
|
+
yield result.value;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
if (error) {
|
|
294
|
+
throw error;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// Cancel function
|
|
299
|
+
const cancel = (): void => {
|
|
300
|
+
cancelled = true;
|
|
301
|
+
cancelGeneration();
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
return {
|
|
305
|
+
stream: tokenGenerator(),
|
|
306
|
+
result: resultPromise,
|
|
307
|
+
cancel,
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Cancel ongoing text generation
|
|
313
|
+
*/
|
|
314
|
+
export function cancelGeneration(): void {
|
|
315
|
+
if (!isNativeModuleAvailable()) {
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
const native = requireNativeModule();
|
|
319
|
+
native.cancelGeneration();
|
|
320
|
+
}
|
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RunAnywhere+VAD.ts
|
|
3
|
+
*
|
|
4
|
+
* Voice Activity Detection extension for RunAnywhere SDK.
|
|
5
|
+
* Matches iOS: RunAnywhere+VAD.swift
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { requireNativeModule, isNativeModuleAvailable } from '../../native';
|
|
9
|
+
import { EventBus } from '../Events';
|
|
10
|
+
import { SDKLogger } from '../../Foundation/Logging/Logger/SDKLogger';
|
|
11
|
+
import type {
|
|
12
|
+
VADConfiguration,
|
|
13
|
+
VADResult,
|
|
14
|
+
SpeechActivityEvent,
|
|
15
|
+
VADSpeechActivityCallback,
|
|
16
|
+
VADAudioBufferCallback,
|
|
17
|
+
VADState,
|
|
18
|
+
} from '../../types/VADTypes';
|
|
19
|
+
|
|
20
|
+
const logger = new SDKLogger('RunAnywhere.VAD');
|
|
21
|
+
|
|
22
|
+
// ============================================================================
|
|
23
|
+
// VAD State Management
|
|
24
|
+
// ============================================================================
|
|
25
|
+
|
|
26
|
+
// Internal VAD state
|
|
27
|
+
let vadState: VADState = {
|
|
28
|
+
isInitialized: false,
|
|
29
|
+
isRunning: false,
|
|
30
|
+
isSpeechActive: false,
|
|
31
|
+
currentProbability: 0,
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// Callbacks
|
|
35
|
+
let speechActivityCallback: VADSpeechActivityCallback | null = null;
|
|
36
|
+
let audioBufferCallback: VADAudioBufferCallback | null = null;
|
|
37
|
+
|
|
38
|
+
// ============================================================================
|
|
39
|
+
// VAD Initialization
|
|
40
|
+
// ============================================================================
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Initialize VAD with default configuration
|
|
44
|
+
* Matches Swift SDK: RunAnywhere.initializeVAD()
|
|
45
|
+
*/
|
|
46
|
+
export async function initializeVAD(config?: VADConfiguration): Promise<void> {
|
|
47
|
+
if (!isNativeModuleAvailable()) {
|
|
48
|
+
throw new Error('Native module not available');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
logger.info('Initializing VAD...');
|
|
52
|
+
|
|
53
|
+
const native = requireNativeModule();
|
|
54
|
+
|
|
55
|
+
// If a config is provided, configure VAD first
|
|
56
|
+
if (config) {
|
|
57
|
+
const configJson = JSON.stringify({
|
|
58
|
+
sampleRate: config.sampleRate ?? 16000,
|
|
59
|
+
frameLength: config.frameLength ?? 0.1,
|
|
60
|
+
energyThreshold: config.energyThreshold ?? 0.005,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// Load VAD model if path provided, otherwise use default
|
|
64
|
+
const loaded = await native.loadVADModel('default', configJson);
|
|
65
|
+
if (!loaded) {
|
|
66
|
+
throw new Error('Failed to initialize VAD');
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
vadState.isInitialized = true;
|
|
71
|
+
logger.info('VAD initialized');
|
|
72
|
+
|
|
73
|
+
EventBus.publish('Voice', { type: 'vadInitialized' });
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Check if VAD is ready
|
|
78
|
+
* Matches Swift SDK: RunAnywhere.isVADReady
|
|
79
|
+
*/
|
|
80
|
+
export async function isVADReady(): Promise<boolean> {
|
|
81
|
+
if (!isNativeModuleAvailable()) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const native = requireNativeModule();
|
|
86
|
+
return native.isVADModelLoaded();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Get current VAD state
|
|
91
|
+
*/
|
|
92
|
+
export function getVADState(): VADState {
|
|
93
|
+
return { ...vadState };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// ============================================================================
|
|
97
|
+
// VAD Model Loading
|
|
98
|
+
// ============================================================================
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Load a VAD model
|
|
102
|
+
*/
|
|
103
|
+
export async function loadVADModel(
|
|
104
|
+
modelPath: string,
|
|
105
|
+
config?: VADConfiguration
|
|
106
|
+
): Promise<boolean> {
|
|
107
|
+
if (!isNativeModuleAvailable()) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
logger.info(`Loading VAD model: ${modelPath}`);
|
|
112
|
+
const native = requireNativeModule();
|
|
113
|
+
|
|
114
|
+
const configJson = config ? JSON.stringify(config) : undefined;
|
|
115
|
+
const result = await native.loadVADModel(modelPath, configJson);
|
|
116
|
+
|
|
117
|
+
if (result) {
|
|
118
|
+
vadState.isInitialized = true;
|
|
119
|
+
logger.info('VAD model loaded');
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Check if a VAD model is loaded
|
|
127
|
+
*/
|
|
128
|
+
export async function isVADModelLoaded(): Promise<boolean> {
|
|
129
|
+
if (!isNativeModuleAvailable()) {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
const native = requireNativeModule();
|
|
133
|
+
return native.isVADModelLoaded();
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Unload the current VAD model
|
|
138
|
+
*/
|
|
139
|
+
export async function unloadVADModel(): Promise<boolean> {
|
|
140
|
+
if (!isNativeModuleAvailable()) {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const native = requireNativeModule();
|
|
145
|
+
const result = await native.unloadVADModel();
|
|
146
|
+
|
|
147
|
+
if (result) {
|
|
148
|
+
vadState.isInitialized = false;
|
|
149
|
+
vadState.isRunning = false;
|
|
150
|
+
vadState.isSpeechActive = false;
|
|
151
|
+
logger.info('VAD model unloaded');
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return result;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// ============================================================================
|
|
158
|
+
// Speech Detection
|
|
159
|
+
// ============================================================================
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Detect speech in audio samples
|
|
163
|
+
* Matches Swift SDK: RunAnywhere.detectSpeech(in:)
|
|
164
|
+
*
|
|
165
|
+
* @param samples Float32Array of audio samples
|
|
166
|
+
* @returns Whether speech was detected
|
|
167
|
+
*/
|
|
168
|
+
export async function detectSpeech(samples: Float32Array): Promise<boolean> {
|
|
169
|
+
if (!isNativeModuleAvailable()) {
|
|
170
|
+
throw new Error('Native module not available');
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Convert Float32Array to base64
|
|
174
|
+
const bytes = new Uint8Array(samples.buffer);
|
|
175
|
+
let binary = '';
|
|
176
|
+
for (let i = 0; i < bytes.byteLength; i++) {
|
|
177
|
+
const byte = bytes[i];
|
|
178
|
+
if (byte !== undefined) {
|
|
179
|
+
binary += String.fromCharCode(byte);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
const audioBase64 = btoa(binary);
|
|
183
|
+
|
|
184
|
+
const result = await processVAD(audioBase64);
|
|
185
|
+
|
|
186
|
+
// Update state
|
|
187
|
+
const wasSpeechActive = vadState.isSpeechActive;
|
|
188
|
+
vadState.isSpeechActive = result.isSpeech;
|
|
189
|
+
vadState.currentProbability = result.probability;
|
|
190
|
+
|
|
191
|
+
// Emit speech activity events
|
|
192
|
+
if (result.isSpeech && !wasSpeechActive) {
|
|
193
|
+
if (speechActivityCallback) {
|
|
194
|
+
speechActivityCallback('started');
|
|
195
|
+
}
|
|
196
|
+
EventBus.publish('Voice', { type: 'speechStarted' });
|
|
197
|
+
} else if (!result.isSpeech && wasSpeechActive) {
|
|
198
|
+
if (speechActivityCallback) {
|
|
199
|
+
speechActivityCallback('ended');
|
|
200
|
+
}
|
|
201
|
+
EventBus.publish('Voice', { type: 'speechEnded' });
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Forward to audio buffer callback if set
|
|
205
|
+
if (audioBufferCallback) {
|
|
206
|
+
audioBufferCallback(samples);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return result.isSpeech;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Process audio for voice activity detection
|
|
214
|
+
* Returns detailed VAD result
|
|
215
|
+
*/
|
|
216
|
+
export async function processVAD(
|
|
217
|
+
audioData: string | ArrayBuffer,
|
|
218
|
+
sampleRate: number = 16000
|
|
219
|
+
): Promise<VADResult> {
|
|
220
|
+
if (!isNativeModuleAvailable()) {
|
|
221
|
+
return { isSpeech: false, probability: 0 };
|
|
222
|
+
}
|
|
223
|
+
const native = requireNativeModule();
|
|
224
|
+
|
|
225
|
+
let audioBase64: string;
|
|
226
|
+
if (typeof audioData === 'string') {
|
|
227
|
+
audioBase64 = audioData;
|
|
228
|
+
} else {
|
|
229
|
+
const bytes = new Uint8Array(audioData);
|
|
230
|
+
let binary = '';
|
|
231
|
+
for (let i = 0; i < bytes.byteLength; i++) {
|
|
232
|
+
const byte = bytes[i];
|
|
233
|
+
if (byte !== undefined) {
|
|
234
|
+
binary += String.fromCharCode(byte);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
audioBase64 = btoa(binary);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const optionsJson = JSON.stringify({ sampleRate });
|
|
241
|
+
const resultJson = await native.processVAD(audioBase64, optionsJson);
|
|
242
|
+
|
|
243
|
+
try {
|
|
244
|
+
const result = JSON.parse(resultJson);
|
|
245
|
+
return {
|
|
246
|
+
isSpeech: result.isSpeech ?? false,
|
|
247
|
+
probability: result.speechProbability ?? result.probability ?? 0,
|
|
248
|
+
startTime: result.startTime,
|
|
249
|
+
endTime: result.endTime,
|
|
250
|
+
};
|
|
251
|
+
} catch {
|
|
252
|
+
return { isSpeech: false, probability: 0 };
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// ============================================================================
|
|
257
|
+
// VAD Control
|
|
258
|
+
// ============================================================================
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Start VAD processing
|
|
262
|
+
* Matches Swift SDK: RunAnywhere.startVAD()
|
|
263
|
+
*/
|
|
264
|
+
export async function startVAD(): Promise<void> {
|
|
265
|
+
if (!vadState.isInitialized) {
|
|
266
|
+
await initializeVAD();
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
vadState.isRunning = true;
|
|
270
|
+
logger.info('VAD started');
|
|
271
|
+
|
|
272
|
+
EventBus.publish('Voice', { type: 'vadStarted' });
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Stop VAD processing
|
|
277
|
+
* Matches Swift SDK: RunAnywhere.stopVAD()
|
|
278
|
+
*/
|
|
279
|
+
export async function stopVAD(): Promise<void> {
|
|
280
|
+
vadState.isRunning = false;
|
|
281
|
+
vadState.isSpeechActive = false;
|
|
282
|
+
vadState.currentProbability = 0;
|
|
283
|
+
|
|
284
|
+
logger.info('VAD stopped');
|
|
285
|
+
EventBus.publish('Voice', { type: 'vadStopped' });
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Reset VAD state
|
|
290
|
+
*/
|
|
291
|
+
export async function resetVAD(): Promise<void> {
|
|
292
|
+
if (!isNativeModuleAvailable()) {
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
const native = requireNativeModule();
|
|
297
|
+
await native.resetVAD();
|
|
298
|
+
|
|
299
|
+
vadState.isSpeechActive = false;
|
|
300
|
+
vadState.currentProbability = 0;
|
|
301
|
+
|
|
302
|
+
logger.debug('VAD state reset');
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// ============================================================================
|
|
306
|
+
// Callbacks
|
|
307
|
+
// ============================================================================
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Set VAD speech activity callback
|
|
311
|
+
* Matches Swift SDK: RunAnywhere.setVADSpeechActivityCallback(_:)
|
|
312
|
+
*
|
|
313
|
+
* @param callback Callback invoked when speech state changes
|
|
314
|
+
*/
|
|
315
|
+
export function setVADSpeechActivityCallback(
|
|
316
|
+
callback: VADSpeechActivityCallback | null
|
|
317
|
+
): void {
|
|
318
|
+
speechActivityCallback = callback;
|
|
319
|
+
logger.debug('VAD speech activity callback set');
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Set VAD audio buffer callback
|
|
324
|
+
* Matches Swift SDK: RunAnywhere.setVADAudioBufferCallback(_:)
|
|
325
|
+
*
|
|
326
|
+
* @param callback Callback invoked with audio samples
|
|
327
|
+
*/
|
|
328
|
+
export function setVADAudioBufferCallback(
|
|
329
|
+
callback: VADAudioBufferCallback | null
|
|
330
|
+
): void {
|
|
331
|
+
audioBufferCallback = callback;
|
|
332
|
+
logger.debug('VAD audio buffer callback set');
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// ============================================================================
|
|
336
|
+
// Cleanup
|
|
337
|
+
// ============================================================================
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Cleanup VAD resources
|
|
341
|
+
* Matches Swift SDK: RunAnywhere.cleanupVAD()
|
|
342
|
+
*/
|
|
343
|
+
export async function cleanupVAD(): Promise<void> {
|
|
344
|
+
await stopVAD();
|
|
345
|
+
await unloadVADModel();
|
|
346
|
+
|
|
347
|
+
speechActivityCallback = null;
|
|
348
|
+
audioBufferCallback = null;
|
|
349
|
+
|
|
350
|
+
vadState = {
|
|
351
|
+
isInitialized: false,
|
|
352
|
+
isRunning: false,
|
|
353
|
+
isSpeechActive: false,
|
|
354
|
+
currentProbability: 0,
|
|
355
|
+
};
|
|
356
|
+
|
|
357
|
+
logger.info('VAD cleaned up');
|
|
358
|
+
EventBus.publish('Voice', { type: 'vadCleanedUp' });
|
|
359
|
+
}
|