@runanywhere/core 0.17.8 → 0.18.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/README.md +218 -2
- package/RunAnywhereCore.podspec +1 -0
- package/android/CMakeLists.txt +24 -2
- package/android/build.gradle +61 -9
- package/android/src/main/cpp/cpp-adapter.cpp +51 -3
- package/android/src/main/include/rac/backends/rac_vlm_llamacpp.h +216 -0
- package/android/src/main/include/rac/core/capabilities/rac_lifecycle.h +3 -1
- package/android/src/main/include/rac/core/rac_core.h +11 -0
- package/android/src/main/include/rac/core/rac_types.h +8 -6
- package/android/src/main/include/rac/features/diffusion/rac_diffusion.h +22 -0
- package/android/src/main/include/rac/features/diffusion/rac_diffusion_component.h +263 -0
- package/android/src/main/include/rac/features/diffusion/rac_diffusion_model_registry.h +358 -0
- package/android/src/main/include/rac/features/diffusion/rac_diffusion_service.h +187 -0
- package/android/src/main/include/rac/features/diffusion/rac_diffusion_tokenizer.h +167 -0
- package/android/src/main/include/rac/features/diffusion/rac_diffusion_types.h +454 -0
- package/android/src/main/include/rac/features/llm/rac_tool_calling.h +373 -0
- package/android/src/main/include/rac/features/platform/rac_diffusion_platform.h +305 -0
- package/android/src/main/include/rac/features/vad/rac_vad_energy.h +1 -1
- package/android/src/main/include/rac/features/vlm/rac_vlm.h +16 -0
- package/android/src/main/include/rac/features/vlm/rac_vlm_component.h +168 -0
- package/android/src/main/include/rac/features/vlm/rac_vlm_service.h +206 -0
- package/android/src/main/include/rac/features/vlm/rac_vlm_types.h +417 -0
- package/android/src/main/include/rac/infrastructure/model_management/rac_model_registry.h +15 -0
- package/android/src/main/include/rac/infrastructure/model_management/rac_model_types.h +3 -0
- package/android/src/main/include/rac/utils/rac_image_utils.h +215 -0
- package/android/src/main/java/com/margelo/nitro/runanywhere/PlatformAdapterBridge.kt +201 -1
- 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/android/src/main/jniLibs/x86_64/libc++_shared.so +0 -0
- package/android/src/main/jniLibs/x86_64/libomp.so +0 -0
- package/android/src/main/jniLibs/x86_64/librac_commons.so +0 -0
- package/android/src/main/jniLibs/x86_64/librunanywhere_jni.so +0 -0
- package/cpp/HybridRunAnywhereCore.cpp +263 -163
- package/cpp/HybridRunAnywhereCore.hpp +11 -0
- package/cpp/bridges/InitBridge.cpp +234 -3
- package/cpp/bridges/PlatformDownloadBridge.h +44 -0
- package/cpp/bridges/ToolCallingBridge.cpp +188 -0
- package/cpp/bridges/ToolCallingBridge.hpp +98 -0
- package/cpp/third_party/nlohmann/json.hpp +24765 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/RACommons.h +18 -4
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_core.h +11 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_diffusion.h +22 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_diffusion_component.h +263 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_diffusion_model_registry.h +358 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_diffusion_platform.h +305 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_diffusion_service.h +187 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_diffusion_tokenizer.h +167 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_diffusion_types.h +454 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_endpoints.h +3 -17
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_image_utils.h +215 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_lifecycle.h +3 -1
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_model_assignment.h +4 -20
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_model_registry.h +15 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_model_types.h +3 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_tool_calling.h +373 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_types.h +8 -6
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_vad_energy.h +1 -1
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_vlm.h +16 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_vlm_component.h +168 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_vlm_llamacpp.h +216 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_vlm_service.h +206 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_vlm_types.h +417 -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 +18 -4
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_core.h +11 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_diffusion.h +22 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_diffusion_component.h +263 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_diffusion_model_registry.h +358 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_diffusion_platform.h +305 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_diffusion_service.h +187 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_diffusion_tokenizer.h +167 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_diffusion_types.h +454 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_endpoints.h +3 -17
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_image_utils.h +215 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_lifecycle.h +3 -1
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_model_assignment.h +4 -20
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_model_registry.h +15 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_model_types.h +3 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_tool_calling.h +373 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_types.h +8 -6
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_vad_energy.h +1 -1
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_vlm.h +16 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_vlm_component.h +168 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_vlm_llamacpp.h +216 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_vlm_service.h +206 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_vlm_types.h +417 -0
- package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/RACommons +0 -0
- package/ios/PlatformAdapterBridge.h +24 -1
- package/ios/PlatformAdapterBridge.m +243 -0
- package/nitrogen/generated/shared/c++/HybridRunAnywhereCoreSpec.cpp +4 -0
- package/nitrogen/generated/shared/c++/HybridRunAnywhereCoreSpec.hpp +4 -0
- package/package.json +8 -4
- package/src/Foundation/Security/SecureStorageService.ts +12 -6
- package/src/Public/Extensions/RunAnywhere+Models.ts +5 -3
- package/src/Public/Extensions/RunAnywhere+STT.ts +7 -2
- package/src/Public/Extensions/RunAnywhere+ToolCalling.ts +472 -0
- package/src/Public/Extensions/index.ts +16 -0
- package/src/Public/RunAnywhere.ts +18 -0
- package/src/index.ts +0 -1
- package/src/services/Network/index.ts +0 -1
- package/src/services/index.ts +0 -1
- package/src/specs/RunAnywhereCore.nitro.ts +72 -0
- package/src/types/ToolCallingTypes.ts +198 -0
- package/src/types/index.ts +13 -0
|
@@ -7,13 +7,16 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
#include "InitBridge.hpp"
|
|
10
|
+
#include "PlatformDownloadBridge.h"
|
|
10
11
|
#include "rac_model_paths.h"
|
|
11
12
|
#include "rac_environment.h" // For rac_sdk_init, rac_sdk_config_t
|
|
12
13
|
#include <cstring>
|
|
13
14
|
#include <cstdlib>
|
|
14
15
|
#include <chrono>
|
|
16
|
+
#include <atomic>
|
|
15
17
|
#include <mutex>
|
|
16
18
|
#include <tuple>
|
|
19
|
+
#include <unordered_map>
|
|
17
20
|
|
|
18
21
|
// Platform-specific logging and bridges
|
|
19
22
|
#if defined(ANDROID) || defined(__ANDROID__)
|
|
@@ -48,6 +51,8 @@ extern jmethodID g_getCoreCountMethod;
|
|
|
48
51
|
extern jmethodID g_getArchitectureMethod;
|
|
49
52
|
extern jmethodID g_getGPUFamilyMethod;
|
|
50
53
|
extern jmethodID g_isTabletMethod;
|
|
54
|
+
extern jmethodID g_httpDownloadMethod;
|
|
55
|
+
extern jmethodID g_httpDownloadCancelMethod;
|
|
51
56
|
// HttpResponse field IDs
|
|
52
57
|
extern jfieldID g_httpResponse_successField;
|
|
53
58
|
extern jfieldID g_httpResponse_statusCodeField;
|
|
@@ -427,6 +432,62 @@ namespace AndroidBridge {
|
|
|
427
432
|
jboolean result = env->CallStaticBooleanMethod(g_platformAdapterBridgeClass, g_isTabletMethod);
|
|
428
433
|
return result == JNI_TRUE;
|
|
429
434
|
}
|
|
435
|
+
|
|
436
|
+
rac_result_t httpDownload(const char* url, const char* destinationPath, const char* taskId) {
|
|
437
|
+
JNIEnv* env = getJNIEnv();
|
|
438
|
+
if (!env) return RAC_ERROR_NOT_SUPPORTED;
|
|
439
|
+
|
|
440
|
+
if (!g_platformAdapterBridgeClass || !g_httpDownloadMethod) {
|
|
441
|
+
LOGE("PlatformAdapterBridge class or httpDownload method not cached");
|
|
442
|
+
return RAC_ERROR_NOT_SUPPORTED;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
jstring jUrl = env->NewStringUTF(url ? url : "");
|
|
446
|
+
jstring jDest = env->NewStringUTF(destinationPath ? destinationPath : "");
|
|
447
|
+
jstring jTaskId = env->NewStringUTF(taskId ? taskId : "");
|
|
448
|
+
|
|
449
|
+
jint result = env->CallStaticIntMethod(g_platformAdapterBridgeClass,
|
|
450
|
+
g_httpDownloadMethod,
|
|
451
|
+
jUrl,
|
|
452
|
+
jDest,
|
|
453
|
+
jTaskId);
|
|
454
|
+
|
|
455
|
+
env->DeleteLocalRef(jUrl);
|
|
456
|
+
env->DeleteLocalRef(jDest);
|
|
457
|
+
env->DeleteLocalRef(jTaskId);
|
|
458
|
+
|
|
459
|
+
if (env->ExceptionCheck()) {
|
|
460
|
+
env->ExceptionClear();
|
|
461
|
+
LOGE("Exception in httpDownload");
|
|
462
|
+
return RAC_ERROR_DOWNLOAD_FAILED;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
return static_cast<rac_result_t>(result);
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
bool httpDownloadCancel(const char* taskId) {
|
|
469
|
+
JNIEnv* env = getJNIEnv();
|
|
470
|
+
if (!env) return false;
|
|
471
|
+
|
|
472
|
+
if (!g_platformAdapterBridgeClass || !g_httpDownloadCancelMethod) {
|
|
473
|
+
LOGE("PlatformAdapterBridge class or httpDownloadCancel method not cached");
|
|
474
|
+
return false;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
jstring jTaskId = env->NewStringUTF(taskId ? taskId : "");
|
|
478
|
+
jboolean result = env->CallStaticBooleanMethod(g_platformAdapterBridgeClass,
|
|
479
|
+
g_httpDownloadCancelMethod,
|
|
480
|
+
jTaskId);
|
|
481
|
+
env->DeleteLocalRef(jTaskId);
|
|
482
|
+
|
|
483
|
+
if (env->ExceptionCheck()) {
|
|
484
|
+
env->ExceptionClear();
|
|
485
|
+
LOGE("Exception in httpDownloadCancel");
|
|
486
|
+
return false;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
return result == JNI_TRUE;
|
|
490
|
+
}
|
|
430
491
|
} // namespace AndroidBridge
|
|
431
492
|
#elif defined(__APPLE__)
|
|
432
493
|
#include <cstdio>
|
|
@@ -461,6 +522,14 @@ extern "C" {
|
|
|
461
522
|
char** outResponseBody,
|
|
462
523
|
char** outErrorMessage
|
|
463
524
|
);
|
|
525
|
+
|
|
526
|
+
int PlatformAdapter_httpDownload(
|
|
527
|
+
const char* url,
|
|
528
|
+
const char* destinationPath,
|
|
529
|
+
const char* taskId
|
|
530
|
+
);
|
|
531
|
+
|
|
532
|
+
bool PlatformAdapter_httpDownloadCancel(const char* taskId);
|
|
464
533
|
}
|
|
465
534
|
#define LOGI(...) printf("[InitBridge] "); printf(__VA_ARGS__); printf("\n")
|
|
466
535
|
#define LOGD(...) printf("[InitBridge DEBUG] "); printf(__VA_ARGS__); printf("\n")
|
|
@@ -483,6 +552,20 @@ namespace bridges {
|
|
|
483
552
|
|
|
484
553
|
static PlatformCallbacks* g_platformCallbacks = nullptr;
|
|
485
554
|
|
|
555
|
+
// =============================================================================
|
|
556
|
+
// HTTP download callback state (platform adapter)
|
|
557
|
+
// =============================================================================
|
|
558
|
+
|
|
559
|
+
struct http_download_context {
|
|
560
|
+
rac_http_progress_callback_fn progress_callback;
|
|
561
|
+
rac_http_complete_callback_fn complete_callback;
|
|
562
|
+
void* user_data;
|
|
563
|
+
};
|
|
564
|
+
|
|
565
|
+
static std::mutex g_http_download_mutex;
|
|
566
|
+
static std::unordered_map<std::string, http_download_context> g_http_downloads;
|
|
567
|
+
static std::atomic<uint64_t> g_http_download_counter{0};
|
|
568
|
+
|
|
486
569
|
// =============================================================================
|
|
487
570
|
// C Callback Implementations (called by RACommons)
|
|
488
571
|
// =============================================================================
|
|
@@ -702,6 +785,134 @@ static void platformTrackErrorCallback(const char* errorJson, void* userData) {
|
|
|
702
785
|
}
|
|
703
786
|
}
|
|
704
787
|
|
|
788
|
+
// =============================================================================
|
|
789
|
+
// HTTP Download Callbacks (Platform Adapter)
|
|
790
|
+
// =============================================================================
|
|
791
|
+
|
|
792
|
+
static int reportHttpDownloadProgressInternal(const char* task_id,
|
|
793
|
+
int64_t downloaded_bytes,
|
|
794
|
+
int64_t total_bytes) {
|
|
795
|
+
if (!task_id) {
|
|
796
|
+
return RAC_ERROR_INVALID_ARGUMENT;
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
std::lock_guard<std::mutex> lock(g_http_download_mutex);
|
|
800
|
+
auto it = g_http_downloads.find(task_id);
|
|
801
|
+
if (it == g_http_downloads.end()) {
|
|
802
|
+
return RAC_ERROR_NOT_FOUND;
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
if (it->second.progress_callback) {
|
|
806
|
+
it->second.progress_callback(downloaded_bytes, total_bytes, it->second.user_data);
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
return RAC_SUCCESS;
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
static int reportHttpDownloadCompleteInternal(const char* task_id,
|
|
813
|
+
int result,
|
|
814
|
+
const char* downloaded_path) {
|
|
815
|
+
if (!task_id) {
|
|
816
|
+
return RAC_ERROR_INVALID_ARGUMENT;
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
http_download_context ctx{};
|
|
820
|
+
{
|
|
821
|
+
std::lock_guard<std::mutex> lock(g_http_download_mutex);
|
|
822
|
+
auto it = g_http_downloads.find(task_id);
|
|
823
|
+
if (it == g_http_downloads.end()) {
|
|
824
|
+
return RAC_ERROR_NOT_FOUND;
|
|
825
|
+
}
|
|
826
|
+
ctx = it->second;
|
|
827
|
+
g_http_downloads.erase(it);
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
if (ctx.complete_callback) {
|
|
831
|
+
ctx.complete_callback(static_cast<rac_result_t>(result), downloaded_path, ctx.user_data);
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
return RAC_SUCCESS;
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
static rac_result_t platformHttpDownloadCallback(const char* url,
|
|
838
|
+
const char* destination_path,
|
|
839
|
+
rac_http_progress_callback_fn progress_callback,
|
|
840
|
+
rac_http_complete_callback_fn complete_callback,
|
|
841
|
+
void* callback_user_data,
|
|
842
|
+
char** out_task_id,
|
|
843
|
+
void* user_data) {
|
|
844
|
+
(void)user_data;
|
|
845
|
+
|
|
846
|
+
if (!url || !destination_path || !out_task_id) {
|
|
847
|
+
return RAC_ERROR_INVALID_ARGUMENT;
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
std::string task_id =
|
|
851
|
+
"http_" + std::to_string(g_http_download_counter.fetch_add(1, std::memory_order_relaxed));
|
|
852
|
+
|
|
853
|
+
*out_task_id = strdup(task_id.c_str());
|
|
854
|
+
if (!*out_task_id) {
|
|
855
|
+
return RAC_ERROR_OUT_OF_MEMORY;
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
{
|
|
859
|
+
std::lock_guard<std::mutex> lock(g_http_download_mutex);
|
|
860
|
+
g_http_downloads[task_id] = {progress_callback, complete_callback, callback_user_data};
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
rac_result_t start_result = RAC_ERROR_NOT_SUPPORTED;
|
|
864
|
+
|
|
865
|
+
#if defined(ANDROID) || defined(__ANDROID__)
|
|
866
|
+
start_result = AndroidBridge::httpDownload(url, destination_path, task_id.c_str());
|
|
867
|
+
#elif defined(__APPLE__)
|
|
868
|
+
start_result = static_cast<rac_result_t>(
|
|
869
|
+
PlatformAdapter_httpDownload(url, destination_path, task_id.c_str()));
|
|
870
|
+
#endif
|
|
871
|
+
|
|
872
|
+
if (start_result != RAC_SUCCESS) {
|
|
873
|
+
http_download_context ctx{};
|
|
874
|
+
{
|
|
875
|
+
std::lock_guard<std::mutex> lock(g_http_download_mutex);
|
|
876
|
+
auto it = g_http_downloads.find(task_id);
|
|
877
|
+
if (it != g_http_downloads.end()) {
|
|
878
|
+
ctx = it->second;
|
|
879
|
+
g_http_downloads.erase(it);
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
if (ctx.complete_callback) {
|
|
884
|
+
ctx.complete_callback(start_result, nullptr, ctx.user_data);
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
return start_result;
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
static rac_result_t platformHttpDownloadCancelCallback(const char* task_id, void* user_data) {
|
|
892
|
+
(void)user_data;
|
|
893
|
+
|
|
894
|
+
if (!task_id) {
|
|
895
|
+
return RAC_ERROR_INVALID_ARGUMENT;
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
{
|
|
899
|
+
std::lock_guard<std::mutex> lock(g_http_download_mutex);
|
|
900
|
+
if (g_http_downloads.find(task_id) == g_http_downloads.end()) {
|
|
901
|
+
return RAC_ERROR_NOT_FOUND;
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
bool cancelled = false;
|
|
906
|
+
|
|
907
|
+
#if defined(ANDROID) || defined(__ANDROID__)
|
|
908
|
+
cancelled = AndroidBridge::httpDownloadCancel(task_id);
|
|
909
|
+
#elif defined(__APPLE__)
|
|
910
|
+
cancelled = PlatformAdapter_httpDownloadCancel(task_id);
|
|
911
|
+
#endif
|
|
912
|
+
|
|
913
|
+
return cancelled ? RAC_SUCCESS : RAC_ERROR_CANCELLED;
|
|
914
|
+
}
|
|
915
|
+
|
|
705
916
|
// =============================================================================
|
|
706
917
|
// InitBridge Implementation
|
|
707
918
|
// =============================================================================
|
|
@@ -757,9 +968,9 @@ void InitBridge::registerPlatformAdapter() {
|
|
|
757
968
|
// Error tracking
|
|
758
969
|
adapter_.track_error = platformTrackErrorCallback;
|
|
759
970
|
|
|
760
|
-
// HTTP download (
|
|
761
|
-
adapter_.http_download =
|
|
762
|
-
adapter_.http_download_cancel =
|
|
971
|
+
// HTTP download (platform adapter)
|
|
972
|
+
adapter_.http_download = platformHttpDownloadCallback;
|
|
973
|
+
adapter_.http_download_cancel = platformHttpDownloadCancelCallback;
|
|
763
974
|
|
|
764
975
|
// Archive extraction (handled by JS layer)
|
|
765
976
|
adapter_.extract_archive = nullptr;
|
|
@@ -1271,3 +1482,23 @@ std::tuple<bool, int, std::string, std::string> InitBridge::httpPostSync(
|
|
|
1271
1482
|
|
|
1272
1483
|
} // namespace bridges
|
|
1273
1484
|
} // namespace runanywhere
|
|
1485
|
+
|
|
1486
|
+
// =============================================================================
|
|
1487
|
+
// Global C API for platform download reporting
|
|
1488
|
+
// =============================================================================
|
|
1489
|
+
|
|
1490
|
+
extern "C" int RunAnywhereHttpDownloadReportProgress(const char* task_id,
|
|
1491
|
+
int64_t downloaded_bytes,
|
|
1492
|
+
int64_t total_bytes) {
|
|
1493
|
+
return runanywhere::bridges::reportHttpDownloadProgressInternal(task_id,
|
|
1494
|
+
downloaded_bytes,
|
|
1495
|
+
total_bytes);
|
|
1496
|
+
}
|
|
1497
|
+
|
|
1498
|
+
extern "C" int RunAnywhereHttpDownloadReportComplete(const char* task_id,
|
|
1499
|
+
int result,
|
|
1500
|
+
const char* downloaded_path) {
|
|
1501
|
+
return runanywhere::bridges::reportHttpDownloadCompleteInternal(task_id,
|
|
1502
|
+
result,
|
|
1503
|
+
downloaded_path);
|
|
1504
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PlatformDownloadBridge.h
|
|
3
|
+
*
|
|
4
|
+
* C callbacks for platform HTTP download progress/completion reporting.
|
|
5
|
+
* Used by iOS/Android platform adapters to report async download state
|
|
6
|
+
* back into the C++ bridge.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
#ifndef RUNANYWHERE_PLATFORM_DOWNLOAD_BRIDGE_H
|
|
10
|
+
#define RUNANYWHERE_PLATFORM_DOWNLOAD_BRIDGE_H
|
|
11
|
+
|
|
12
|
+
#include <stdint.h>
|
|
13
|
+
|
|
14
|
+
#ifdef __cplusplus
|
|
15
|
+
extern "C" {
|
|
16
|
+
#endif
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Report HTTP download progress for a task.
|
|
20
|
+
* @param task_id Task identifier
|
|
21
|
+
* @param downloaded_bytes Bytes downloaded so far
|
|
22
|
+
* @param total_bytes Total bytes (0 if unknown)
|
|
23
|
+
* @return RAC_SUCCESS on success, error code otherwise
|
|
24
|
+
*/
|
|
25
|
+
int RunAnywhereHttpDownloadReportProgress(const char* task_id,
|
|
26
|
+
int64_t downloaded_bytes,
|
|
27
|
+
int64_t total_bytes);
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Report HTTP download completion for a task.
|
|
31
|
+
* @param task_id Task identifier
|
|
32
|
+
* @param result RAC_SUCCESS or error code
|
|
33
|
+
* @param downloaded_path Path to downloaded file (NULL on failure)
|
|
34
|
+
* @return RAC_SUCCESS on success, error code otherwise
|
|
35
|
+
*/
|
|
36
|
+
int RunAnywhereHttpDownloadReportComplete(const char* task_id,
|
|
37
|
+
int result,
|
|
38
|
+
const char* downloaded_path);
|
|
39
|
+
|
|
40
|
+
#ifdef __cplusplus
|
|
41
|
+
} // extern "C"
|
|
42
|
+
#endif
|
|
43
|
+
|
|
44
|
+
#endif // RUNANYWHERE_PLATFORM_DOWNLOAD_BRIDGE_H
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file ToolCallingBridge.cpp
|
|
3
|
+
* @brief Tool Calling bridge implementation - THIN WRAPPER
|
|
4
|
+
*
|
|
5
|
+
* *** ALL LOGIC IS IN runanywhere-commons (rac_tool_calling.h) ***
|
|
6
|
+
*
|
|
7
|
+
* This bridge just wraps the C API functions from commons.
|
|
8
|
+
* NO LOCAL PARSING LOGIC - everything calls through to commons.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
#include "ToolCallingBridge.hpp"
|
|
12
|
+
#include <rac_tool_calling.h>
|
|
13
|
+
#include <nlohmann/json.hpp>
|
|
14
|
+
#include <cstring>
|
|
15
|
+
|
|
16
|
+
using json = nlohmann::json;
|
|
17
|
+
|
|
18
|
+
namespace runanywhere {
|
|
19
|
+
namespace bridges {
|
|
20
|
+
|
|
21
|
+
ToolCallingBridge& ToolCallingBridge::shared() {
|
|
22
|
+
static ToolCallingBridge instance;
|
|
23
|
+
return instance;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
std::string ToolCallingBridge::parseToolCall(const std::string& llmOutput) {
|
|
27
|
+
rac_tool_call_t result = {}; // Zero-initialize for safety
|
|
28
|
+
rac_result_t rc = rac_tool_call_parse(llmOutput.c_str(), &result);
|
|
29
|
+
|
|
30
|
+
// Handle parse failure defensively - return safe default
|
|
31
|
+
if (rc != RAC_SUCCESS) {
|
|
32
|
+
json fallback;
|
|
33
|
+
fallback["hasToolCall"] = false;
|
|
34
|
+
fallback["cleanText"] = llmOutput;
|
|
35
|
+
return fallback.dump();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Build JSON response using nlohmann/json
|
|
39
|
+
json response;
|
|
40
|
+
response["hasToolCall"] = result.has_tool_call == RAC_TRUE;
|
|
41
|
+
response["cleanText"] = result.clean_text ? result.clean_text : llmOutput;
|
|
42
|
+
|
|
43
|
+
if (result.has_tool_call == RAC_TRUE) {
|
|
44
|
+
response["toolName"] = result.tool_name ? result.tool_name : "";
|
|
45
|
+
|
|
46
|
+
if (result.arguments_json) {
|
|
47
|
+
try {
|
|
48
|
+
response["argumentsJson"] = json::parse(result.arguments_json);
|
|
49
|
+
} catch (...) {
|
|
50
|
+
response["argumentsJson"] = json::object();
|
|
51
|
+
}
|
|
52
|
+
} else {
|
|
53
|
+
response["argumentsJson"] = json::object();
|
|
54
|
+
}
|
|
55
|
+
response["callId"] = result.call_id;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
rac_tool_call_free(&result);
|
|
59
|
+
return response.dump();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
std::string ToolCallingBridge::formatToolsPrompt(const std::string& toolsJson, const std::string& format) {
|
|
63
|
+
if (toolsJson.empty() || toolsJson == "[]") {
|
|
64
|
+
return "";
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
char* prompt = nullptr;
|
|
68
|
+
rac_result_t rc = rac_tool_call_format_prompt_json_with_format_name(
|
|
69
|
+
toolsJson.c_str(),
|
|
70
|
+
format.c_str(),
|
|
71
|
+
&prompt
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
if (rc != RAC_SUCCESS || !prompt) {
|
|
75
|
+
return "";
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
std::string result(prompt);
|
|
79
|
+
rac_free(prompt);
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
std::string ToolCallingBridge::buildInitialPrompt(
|
|
84
|
+
const std::string& userPrompt,
|
|
85
|
+
const std::string& toolsJson,
|
|
86
|
+
const std::string& optionsJson
|
|
87
|
+
) {
|
|
88
|
+
// Start with default options
|
|
89
|
+
rac_tool_calling_options_t options = {
|
|
90
|
+
5, // max_tool_calls
|
|
91
|
+
RAC_TRUE, // auto_execute
|
|
92
|
+
0.7f, // temperature
|
|
93
|
+
1024, // max_tokens
|
|
94
|
+
nullptr, // system_prompt
|
|
95
|
+
RAC_FALSE, // replace_system_prompt
|
|
96
|
+
RAC_FALSE, // keep_tools_available
|
|
97
|
+
RAC_TOOL_FORMAT_DEFAULT // format
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
// Parse optionsJson if provided
|
|
101
|
+
if (!optionsJson.empty()) {
|
|
102
|
+
try {
|
|
103
|
+
json opts = json::parse(optionsJson);
|
|
104
|
+
|
|
105
|
+
if (opts.contains("maxToolCalls") && opts["maxToolCalls"].is_number_integer()) {
|
|
106
|
+
options.max_tool_calls = opts["maxToolCalls"].get<int32_t>();
|
|
107
|
+
}
|
|
108
|
+
if (opts.contains("autoExecute") && opts["autoExecute"].is_boolean()) {
|
|
109
|
+
options.auto_execute = opts["autoExecute"].get<bool>() ? RAC_TRUE : RAC_FALSE;
|
|
110
|
+
}
|
|
111
|
+
if (opts.contains("temperature") && opts["temperature"].is_number()) {
|
|
112
|
+
options.temperature = opts["temperature"].get<float>();
|
|
113
|
+
}
|
|
114
|
+
if (opts.contains("maxTokens") && opts["maxTokens"].is_number_integer()) {
|
|
115
|
+
options.max_tokens = opts["maxTokens"].get<int32_t>();
|
|
116
|
+
}
|
|
117
|
+
if (opts.contains("format") && opts["format"].is_string()) {
|
|
118
|
+
options.format = rac_tool_call_format_from_name(opts["format"].get<std::string>().c_str());
|
|
119
|
+
}
|
|
120
|
+
if (opts.contains("replaceSystemPrompt") && opts["replaceSystemPrompt"].is_boolean()) {
|
|
121
|
+
options.replace_system_prompt = opts["replaceSystemPrompt"].get<bool>() ? RAC_TRUE : RAC_FALSE;
|
|
122
|
+
}
|
|
123
|
+
if (opts.contains("keepToolsAvailable") && opts["keepToolsAvailable"].is_boolean()) {
|
|
124
|
+
options.keep_tools_available = opts["keepToolsAvailable"].get<bool>() ? RAC_TRUE : RAC_FALSE;
|
|
125
|
+
}
|
|
126
|
+
} catch (...) {
|
|
127
|
+
// JSON parse failed, keep defaults
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
char* prompt = nullptr;
|
|
132
|
+
rac_result_t rc = rac_tool_call_build_initial_prompt(
|
|
133
|
+
userPrompt.c_str(),
|
|
134
|
+
toolsJson.c_str(),
|
|
135
|
+
&options,
|
|
136
|
+
&prompt
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
if (rc != RAC_SUCCESS || !prompt) {
|
|
140
|
+
return userPrompt;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
std::string result(prompt);
|
|
144
|
+
rac_free(prompt);
|
|
145
|
+
return result;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
std::string ToolCallingBridge::buildFollowupPrompt(
|
|
149
|
+
const std::string& originalPrompt,
|
|
150
|
+
const std::string& toolsPrompt,
|
|
151
|
+
const std::string& toolName,
|
|
152
|
+
const std::string& resultJson,
|
|
153
|
+
bool keepToolsAvailable
|
|
154
|
+
) {
|
|
155
|
+
char* prompt = nullptr;
|
|
156
|
+
rac_result_t rc = rac_tool_call_build_followup_prompt(
|
|
157
|
+
originalPrompt.c_str(),
|
|
158
|
+
toolsPrompt.empty() ? nullptr : toolsPrompt.c_str(),
|
|
159
|
+
toolName.c_str(),
|
|
160
|
+
resultJson.c_str(),
|
|
161
|
+
keepToolsAvailable ? RAC_TRUE : RAC_FALSE,
|
|
162
|
+
&prompt
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
if (rc != RAC_SUCCESS || !prompt) {
|
|
166
|
+
return "";
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
std::string result(prompt);
|
|
170
|
+
rac_free(prompt);
|
|
171
|
+
return result;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
std::string ToolCallingBridge::normalizeJson(const std::string& jsonStr) {
|
|
175
|
+
char* normalized = nullptr;
|
|
176
|
+
rac_result_t rc = rac_tool_call_normalize_json(jsonStr.c_str(), &normalized);
|
|
177
|
+
|
|
178
|
+
if (rc != RAC_SUCCESS || !normalized) {
|
|
179
|
+
return jsonStr;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
std::string result(normalized);
|
|
183
|
+
rac_free(normalized);
|
|
184
|
+
return result;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
} // namespace bridges
|
|
188
|
+
} // namespace runanywhere
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file ToolCallingBridge.hpp
|
|
3
|
+
* @brief Tool Calling bridge for React Native - THIN WRAPPER
|
|
4
|
+
*
|
|
5
|
+
* *** SINGLE SOURCE OF TRUTH FOR TOOL CALLING LOGIC IS IN COMMONS C++ ***
|
|
6
|
+
*
|
|
7
|
+
* All parsing logic is in runanywhere-commons (rac_tool_calling.h).
|
|
8
|
+
* This bridge just wraps the C API for JSI access.
|
|
9
|
+
*
|
|
10
|
+
* ARCHITECTURE:
|
|
11
|
+
* - Commons C++: ALL parsing, prompt formatting, JSON normalization
|
|
12
|
+
* - This bridge: Thin wrapper that calls rac_tool_call_* functions
|
|
13
|
+
* - TypeScript: Tool registry, execution (needs JS APIs)
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
#pragma once
|
|
17
|
+
|
|
18
|
+
#include <string>
|
|
19
|
+
|
|
20
|
+
namespace runanywhere {
|
|
21
|
+
namespace bridges {
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Tool Calling bridge - thin wrapper around commons API
|
|
25
|
+
*
|
|
26
|
+
* *** NO LOCAL PARSING LOGIC - ALL CALLS GO TO COMMONS ***
|
|
27
|
+
*/
|
|
28
|
+
class ToolCallingBridge {
|
|
29
|
+
public:
|
|
30
|
+
static ToolCallingBridge& shared();
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Format tool definitions into a system prompt.
|
|
34
|
+
* Calls rac_tool_call_format_prompt_json_with_format_name() from commons.
|
|
35
|
+
*
|
|
36
|
+
* @param toolsJson JSON array of tool definitions
|
|
37
|
+
* @param format Format name ("default" or "lfm2")
|
|
38
|
+
* @return Formatted system prompt string
|
|
39
|
+
*/
|
|
40
|
+
std::string formatToolsPrompt(const std::string& toolsJson, const std::string& format = "default");
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Parse LLM output for tool calls.
|
|
44
|
+
* Calls rac_tool_call_parse() from commons.
|
|
45
|
+
*
|
|
46
|
+
* @param llmOutput Raw LLM output text
|
|
47
|
+
* @return JSON string with hasToolCall, toolName, argumentsJson, cleanText
|
|
48
|
+
*/
|
|
49
|
+
std::string parseToolCall(const std::string& llmOutput);
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Build initial prompt with tools and user query.
|
|
53
|
+
* Calls rac_tool_call_build_initial_prompt() from commons.
|
|
54
|
+
*
|
|
55
|
+
* @param userPrompt User's question/request
|
|
56
|
+
* @param toolsJson JSON array of tool definitions
|
|
57
|
+
* @param optionsJson Options as JSON (nullable)
|
|
58
|
+
* @return Complete formatted prompt
|
|
59
|
+
*/
|
|
60
|
+
std::string buildInitialPrompt(const std::string& userPrompt,
|
|
61
|
+
const std::string& toolsJson,
|
|
62
|
+
const std::string& optionsJson);
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Build follow-up prompt after tool execution.
|
|
66
|
+
* Calls rac_tool_call_build_followup_prompt() from commons.
|
|
67
|
+
*
|
|
68
|
+
* @param originalPrompt Original user prompt
|
|
69
|
+
* @param toolsPrompt Formatted tools prompt (can be empty)
|
|
70
|
+
* @param toolName Name of executed tool
|
|
71
|
+
* @param resultJson Tool result as JSON
|
|
72
|
+
* @param keepToolsAvailable Whether to keep tools in follow-up
|
|
73
|
+
* @return Follow-up prompt string
|
|
74
|
+
*/
|
|
75
|
+
std::string buildFollowupPrompt(const std::string& originalPrompt,
|
|
76
|
+
const std::string& toolsPrompt,
|
|
77
|
+
const std::string& toolName,
|
|
78
|
+
const std::string& resultJson,
|
|
79
|
+
bool keepToolsAvailable);
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Normalize JSON by adding quotes around unquoted keys.
|
|
83
|
+
* Calls rac_tool_call_normalize_json() from commons.
|
|
84
|
+
*
|
|
85
|
+
* @param jsonStr Raw JSON possibly with unquoted keys
|
|
86
|
+
* @return Normalized JSON string
|
|
87
|
+
*/
|
|
88
|
+
std::string normalizeJson(const std::string& jsonStr);
|
|
89
|
+
|
|
90
|
+
private:
|
|
91
|
+
ToolCallingBridge() = default;
|
|
92
|
+
~ToolCallingBridge() = default;
|
|
93
|
+
ToolCallingBridge(const ToolCallingBridge&) = delete;
|
|
94
|
+
ToolCallingBridge& operator=(const ToolCallingBridge&) = delete;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
} // namespace bridges
|
|
98
|
+
} // namespace runanywhere
|