@runanywhere/core 0.17.6 → 0.17.8

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.
@@ -34,17 +34,9 @@ typedef struct rac_assignment_http_response {
34
34
  const char* error_message; // Error message (can be NULL)
35
35
  } rac_assignment_http_response_t;
36
36
 
37
- /**
38
- * @brief Device info for model assignment request
39
- */
40
- typedef struct rac_assignment_device_info {
41
- const char* device_type; // e.g., "iPhone15,2"
42
- const char* platform; // e.g., "iOS"
43
- } rac_assignment_device_info_t;
44
-
45
37
  /**
46
38
  * Make HTTP GET request for model assignments
47
- * @param endpoint Full endpoint URL with query params
39
+ * @param endpoint Endpoint path (e.g., "/api/v1/model-assignments/for-sdk")
48
40
  * @param requires_auth Whether authentication header is required
49
41
  * @param out_response Output parameter for response
50
42
  * @param user_data User-provided context
@@ -54,14 +46,6 @@ typedef rac_result_t (*rac_assignment_http_get_fn)(const char* endpoint, rac_boo
54
46
  rac_assignment_http_response_t* out_response,
55
47
  void* user_data);
56
48
 
57
- /**
58
- * Get device info for model assignment request
59
- * @param out_info Output parameter for device info
60
- * @param user_data User-provided context
61
- */
62
- typedef void (*rac_assignment_get_device_info_fn)(rac_assignment_device_info_t* out_info,
63
- void* user_data);
64
-
65
49
  /**
66
50
  * @brief Callback structure for model assignment operations
67
51
  */
@@ -69,11 +53,11 @@ typedef struct rac_assignment_callbacks {
69
53
  /** Make HTTP GET request */
70
54
  rac_assignment_http_get_fn http_get;
71
55
 
72
- /** Get device info for request */
73
- rac_assignment_get_device_info_fn get_device_info;
74
-
75
56
  /** User data passed to all callbacks */
76
57
  void* user_data;
58
+
59
+ /** If true, automatically fetch models after callbacks are registered */
60
+ rac_bool_t auto_fetch;
77
61
  } rac_assignment_callbacks_t;
78
62
 
79
63
  // =============================================================================
@@ -62,24 +62,10 @@ const char* rac_endpoint_device_registration(rac_environment_t env);
62
62
  const char* rac_endpoint_telemetry(rac_environment_t env);
63
63
 
64
64
  /**
65
- * @brief Build model assignments endpoint with query params
66
- * @param device_type Device type (e.g., "iphone", "android_phone")
67
- * @param platform Platform (e.g., "ios", "android")
68
- * @param out_buffer Buffer to write endpoint path
69
- * @param buffer_size Size of buffer
70
- * @return Length of written string, or -1 on error
71
- */
72
- int rac_endpoint_model_assignments(const char* device_type, const char* platform, char* out_buffer,
73
- size_t buffer_size);
74
-
75
- /**
76
- * @brief Build model download endpoint
77
- * @param model_id The model ID
78
- * @param out_buffer Buffer to write endpoint path
79
- * @param buffer_size Size of buffer
80
- * @return Length of written string, or -1 on error
65
+ * @brief Get model assignments endpoint
66
+ * @return Endpoint path string
81
67
  */
82
- int rac_endpoint_model_download(const char* model_id, char* out_buffer, size_t buffer_size);
68
+ const char* rac_endpoint_model_assignments(void);
83
69
 
84
70
  // =============================================================================
85
71
  // Full URL Building
@@ -373,6 +373,66 @@ std::shared_ptr<Promise<bool>> HybridRunAnywhereCore::initialize(
373
373
  }
374
374
  }
375
375
 
376
+ // 9. Initialize model assignments with auto-fetch
377
+ // Set up HTTP GET callback for fetching models from backend
378
+ {
379
+ rac_assignment_callbacks_t callbacks = {};
380
+
381
+ // HTTP GET callback - uses HTTPBridge for network requests
382
+ callbacks.http_get = [](const char* endpoint, rac_bool_t requires_auth,
383
+ rac_assignment_http_response_t* out_response, void* user_data) -> rac_result_t {
384
+ if (!out_response) return RAC_ERROR_NULL_POINTER;
385
+
386
+ try {
387
+ std::string endpointStr = endpoint ? endpoint : "";
388
+ LOGD("Model assignment HTTP GET: %s", endpointStr.c_str());
389
+
390
+ // Use HTTPBridge::execute which calls the registered JS executor
391
+ auto responseOpt = HTTPBridge::shared().execute("GET", endpointStr, "", requires_auth == RAC_TRUE);
392
+
393
+ if (!responseOpt.has_value()) {
394
+ LOGE("HTTP executor not registered");
395
+ out_response->result = RAC_ERROR_HTTP_REQUEST_FAILED;
396
+ out_response->error_message = strdup("HTTP executor not registered");
397
+ return RAC_ERROR_HTTP_REQUEST_FAILED;
398
+ }
399
+
400
+ const auto& response = responseOpt.value();
401
+ if (response.success && !response.body.empty()) {
402
+ out_response->result = RAC_SUCCESS;
403
+ out_response->status_code = response.statusCode;
404
+ out_response->response_body = strdup(response.body.c_str());
405
+ out_response->response_length = response.body.length();
406
+ return RAC_SUCCESS;
407
+ } else {
408
+ out_response->result = RAC_ERROR_HTTP_REQUEST_FAILED;
409
+ out_response->status_code = response.statusCode;
410
+ if (!response.error.empty()) {
411
+ out_response->error_message = strdup(response.error.c_str());
412
+ }
413
+ return RAC_ERROR_HTTP_REQUEST_FAILED;
414
+ }
415
+ } catch (const std::exception& e) {
416
+ LOGE("Model assignment HTTP GET failed: %s", e.what());
417
+ out_response->result = RAC_ERROR_HTTP_REQUEST_FAILED;
418
+ out_response->error_message = strdup(e.what());
419
+ return RAC_ERROR_HTTP_REQUEST_FAILED;
420
+ }
421
+ };
422
+
423
+ callbacks.user_data = nullptr;
424
+ // Note: auto_fetch was removed from rac_assignment_callbacks struct
425
+ // Fetching is now controlled manually via rac_model_assignment_fetch()
426
+
427
+ result = rac_model_assignment_set_callbacks(&callbacks);
428
+ if (result == RAC_SUCCESS) {
429
+ LOGI("Model assignment callbacks registered");
430
+ } else {
431
+ LOGE("Failed to register model assignment callbacks: %d", result);
432
+ // Continue - not fatal, models can be fetched later
433
+ }
434
+ }
435
+
376
436
  LOGI("Core SDK initialized successfully");
377
437
  return true;
378
438
  });
@@ -406,10 +466,10 @@ std::shared_ptr<Promise<std::string>> HybridRunAnywhereCore::getBackendInfo() {
406
466
  return Promise<std::string>::async([]() {
407
467
  // Check if SDK is initialized using the actual InitBridge state
408
468
  bool isInitialized = InitBridge::shared().isInitialized();
409
-
469
+
410
470
  std::string status = isInitialized ? "initialized" : "not_initialized";
411
471
  std::string name = isInitialized ? "RunAnywhere Core" : "Not initialized";
412
-
472
+
413
473
  return buildJsonObject({
414
474
  {"name", jsonString(name)},
415
475
  {"status", jsonString(status)},
@@ -496,8 +556,8 @@ std::shared_ptr<Promise<bool>> HybridRunAnywhereCore::setAuthTokens(
496
556
  // IMPORTANT: Actually store the tokens in AuthBridge!
497
557
  // handleAuthResponse only parses, setAuth stores them
498
558
  AuthBridge::shared().setAuth(response);
499
-
500
- LOGI("Auth tokens set successfully. Token expires in %lld seconds",
559
+
560
+ LOGI("Auth tokens set successfully. Token expires in %lld seconds",
501
561
  static_cast<long long>(response.expiresIn));
502
562
  LOGD("Access token stored (length=%zu)", response.accessToken.length());
503
563
  return true;
@@ -526,7 +586,7 @@ std::shared_ptr<Promise<bool>> HybridRunAnywhereCore::registerDevice(
526
586
 
527
587
  std::string buildToken = extractStringValue(environmentJson, "buildToken", "");
528
588
  std::string supabaseKey = extractStringValue(environmentJson, "supabaseKey", "");
529
-
589
+
530
590
  // For development mode, get build token from C++ dev config if not provided
531
591
  // This matches Swift's CppBridge.DevConfig.buildToken behavior
532
592
  if (buildToken.empty() && env == RAC_ENV_DEVELOPMENT) {
@@ -544,7 +604,7 @@ std::shared_ptr<Promise<bool>> HybridRunAnywhereCore::registerDevice(
544
604
  // Matches Swift's CppBridge+Device.swift get_device_info callback
545
605
  callbacks.getDeviceInfo = []() -> DeviceInfo {
546
606
  DeviceInfo info;
547
-
607
+
548
608
  // Core identification
549
609
  info.deviceId = InitBridge::shared().getPersistentDeviceUUID();
550
610
  // Use actual platform (ios/android) as backend only accepts these values
@@ -557,7 +617,7 @@ std::shared_ptr<Promise<bool>> HybridRunAnywhereCore::registerDevice(
557
617
  #endif
558
618
  // Use centralized SDK version from InitBridge (set from TypeScript SDKConstants)
559
619
  info.sdkVersion = InitBridge::shared().getSdkVersion();
560
-
620
+
561
621
  // Device hardware info from platform-specific code
562
622
  info.deviceModel = InitBridge::shared().getDeviceModel();
563
623
  info.deviceName = info.deviceModel; // Use model as name (React Native doesn't expose device name)
@@ -567,12 +627,12 @@ std::shared_ptr<Promise<bool>> HybridRunAnywhereCore::registerDevice(
567
627
  info.totalMemory = InitBridge::shared().getTotalMemory();
568
628
  info.availableMemory = InitBridge::shared().getAvailableMemory();
569
629
  info.coreCount = InitBridge::shared().getCoreCount();
570
-
630
+
571
631
  // Form factor detection (matches Swift SDK: device.userInterfaceIdiom == .pad)
572
632
  // Uses platform-specific detection via InitBridge::isTablet()
573
633
  bool isTabletDevice = InitBridge::shared().isTablet();
574
634
  info.formFactor = isTabletDevice ? "tablet" : "phone";
575
-
635
+
576
636
  // Platform-specific values
577
637
  #if defined(__APPLE__)
578
638
  info.osName = "iOS";
@@ -590,16 +650,16 @@ std::shared_ptr<Promise<bool>> HybridRunAnywhereCore::registerDevice(
590
650
  info.hasNeuralEngine = false;
591
651
  info.neuralEngineCores = 0;
592
652
  #endif
593
-
653
+
594
654
  // Battery info (not available in React Native easily, use defaults)
595
655
  info.batteryLevel = -1.0; // Unknown
596
656
  info.batteryState = ""; // Unknown
597
657
  info.isLowPowerMode = false;
598
-
658
+
599
659
  // Core distribution (approximate for mobile devices)
600
660
  info.performanceCores = info.coreCount > 4 ? 2 : 1;
601
661
  info.efficiencyCores = info.coreCount - info.performanceCores;
602
-
662
+
603
663
  return info;
604
664
  };
605
665
 
@@ -641,10 +701,10 @@ std::shared_ptr<Promise<bool>> HybridRunAnywhereCore::registerDevice(
641
701
  // NO FALLBACK - credentials must come from C++ config only
642
702
  const char* devUrl = rac_dev_config_get_supabase_url();
643
703
  const char* devKey = rac_dev_config_get_supabase_key();
644
-
704
+
645
705
  baseURL = devUrl ? devUrl : "";
646
706
  apiKey = devKey ? devKey : "";
647
-
707
+
648
708
  if (baseURL.empty()) {
649
709
  LOGW("Development mode but Supabase URL not configured in C++ dev_config");
650
710
  } else {
@@ -654,7 +714,7 @@ std::shared_ptr<Promise<bool>> HybridRunAnywhereCore::registerDevice(
654
714
  // Production/Staging: Use configured Railway URL
655
715
  // These come from SDK initialization (App.tsx -> RunAnywhere.initialize)
656
716
  baseURL = InitBridge::shared().getBaseURL();
657
-
717
+
658
718
  // For production mode, prefer JWT access token (from authentication)
659
719
  // over raw API key. This matches Swift/Kotlin behavior.
660
720
  std::string accessToken = AuthBridge::shared().getAccessToken();
@@ -666,12 +726,12 @@ std::shared_ptr<Promise<bool>> HybridRunAnywhereCore::registerDevice(
666
726
  apiKey = InitBridge::shared().getApiKey();
667
727
  LOGD("Using API key for device registration (not authenticated)");
668
728
  }
669
-
729
+
670
730
  // Fallback to default if not configured
671
731
  if (baseURL.empty()) {
672
732
  baseURL = "https://api.runanywhere.ai";
673
733
  }
674
-
734
+
675
735
  LOGD("Using production config: %s", baseURL.c_str());
676
736
  }
677
737
 
@@ -16,7 +16,6 @@
16
16
  #include "rac_events.h"
17
17
  #include "rac_http_client.h"
18
18
  #include "rac_lifecycle.h"
19
- #include "rac_llm.h"
20
19
  #include "rac_llm_analytics.h"
21
20
  #include "rac_llm_component.h"
22
21
  #include "rac_llm_events.h"
@@ -26,6 +25,7 @@
26
25
  #include "rac_llm_service.h"
27
26
  #include "rac_llm_structured_output.h"
28
27
  #include "rac_llm_types.h"
28
+ #include "rac_llm.h"
29
29
  #include "rac_logger.h"
30
30
  #include "rac_model_assignment.h"
31
31
  #include "rac_model_paths.h"
@@ -36,7 +36,6 @@
36
36
  #include "rac_sdk_state.h"
37
37
  #include "rac_storage_analyzer.h"
38
38
  #include "rac_structured_error.h"
39
- #include "rac_stt.h"
40
39
  #include "rac_stt_analytics.h"
41
40
  #include "rac_stt_component.h"
42
41
  #include "rac_stt_events.h"
@@ -44,9 +43,9 @@
44
43
  #include "rac_stt_service.h"
45
44
  #include "rac_stt_types.h"
46
45
  #include "rac_stt_whispercpp.h"
46
+ #include "rac_stt.h"
47
47
  #include "rac_telemetry_manager.h"
48
48
  #include "rac_telemetry_types.h"
49
- #include "rac_tts.h"
50
49
  #include "rac_tts_analytics.h"
51
50
  #include "rac_tts_component.h"
52
51
  #include "rac_tts_events.h"
@@ -54,8 +53,8 @@
54
53
  #include "rac_tts_platform.h"
55
54
  #include "rac_tts_service.h"
56
55
  #include "rac_tts_types.h"
56
+ #include "rac_tts.h"
57
57
  #include "rac_types.h"
58
- #include "rac_vad.h"
59
58
  #include "rac_vad_analytics.h"
60
59
  #include "rac_vad_component.h"
61
60
  #include "rac_vad_energy.h"
@@ -63,5 +62,6 @@
63
62
  #include "rac_vad_onnx.h"
64
63
  #include "rac_vad_service.h"
65
64
  #include "rac_vad_types.h"
65
+ #include "rac_vad.h"
66
66
  #include "rac_voice_agent.h"
67
67
  #endif
@@ -16,7 +16,6 @@
16
16
  #include "rac_events.h"
17
17
  #include "rac_http_client.h"
18
18
  #include "rac_lifecycle.h"
19
- #include "rac_llm.h"
20
19
  #include "rac_llm_analytics.h"
21
20
  #include "rac_llm_component.h"
22
21
  #include "rac_llm_events.h"
@@ -26,6 +25,7 @@
26
25
  #include "rac_llm_service.h"
27
26
  #include "rac_llm_structured_output.h"
28
27
  #include "rac_llm_types.h"
28
+ #include "rac_llm.h"
29
29
  #include "rac_logger.h"
30
30
  #include "rac_model_assignment.h"
31
31
  #include "rac_model_paths.h"
@@ -36,7 +36,6 @@
36
36
  #include "rac_sdk_state.h"
37
37
  #include "rac_storage_analyzer.h"
38
38
  #include "rac_structured_error.h"
39
- #include "rac_stt.h"
40
39
  #include "rac_stt_analytics.h"
41
40
  #include "rac_stt_component.h"
42
41
  #include "rac_stt_events.h"
@@ -44,9 +43,9 @@
44
43
  #include "rac_stt_service.h"
45
44
  #include "rac_stt_types.h"
46
45
  #include "rac_stt_whispercpp.h"
46
+ #include "rac_stt.h"
47
47
  #include "rac_telemetry_manager.h"
48
48
  #include "rac_telemetry_types.h"
49
- #include "rac_tts.h"
50
49
  #include "rac_tts_analytics.h"
51
50
  #include "rac_tts_component.h"
52
51
  #include "rac_tts_events.h"
@@ -54,8 +53,8 @@
54
53
  #include "rac_tts_platform.h"
55
54
  #include "rac_tts_service.h"
56
55
  #include "rac_tts_types.h"
56
+ #include "rac_tts.h"
57
57
  #include "rac_types.h"
58
- #include "rac_vad.h"
59
58
  #include "rac_vad_analytics.h"
60
59
  #include "rac_vad_component.h"
61
60
  #include "rac_vad_energy.h"
@@ -63,5 +62,6 @@
63
62
  #include "rac_vad_onnx.h"
64
63
  #include "rac_vad_service.h"
65
64
  #include "rac_vad_types.h"
65
+ #include "rac_vad.h"
66
66
  #include "rac_voice_agent.h"
67
67
  #endif
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runanywhere/core",
3
- "version": "0.17.6",
3
+ "version": "0.17.8",
4
4
  "description": "Core SDK for RunAnywhere React Native - includes RACommons bindings, native bridges, and public API",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -67,8 +67,8 @@
67
67
  },
68
68
  "devDependencies": {
69
69
  "@types/react": "~19.1.0",
70
- "nitrogen": "^0.31.10",
71
- "react-native-nitro-modules": "^0.31.10",
70
+ "nitrogen": "^0.33.2",
71
+ "react-native-nitro-modules": "0.33.2",
72
72
  "typescript": "~5.9.2"
73
73
  },
74
74
  "create-react-native-library": {
@@ -135,7 +135,11 @@ export async function getDownloadedModels(): Promise<ModelInfo[]> {
135
135
  // ============================================================================
136
136
 
137
137
  /**
138
- * Fetch model assignments for the current device from the backend
138
+ * Fetch model assignments for the current device from the backend.
139
+ *
140
+ * Note: Model assignments are automatically fetched during SDK initialization
141
+ * (auto-fetch is enabled in the C++ layer). This method retrieves the cached
142
+ * models from the registry.
139
143
  */
140
144
  export async function fetchModelAssignments(
141
145
  forceRefresh = false,
@@ -150,7 +154,7 @@ export async function fetchModelAssignments(
150
154
 
151
155
  logger.info('Fetching model assignments...');
152
156
 
153
- // Fetch model assignments via native or fallback to ModelRegistry
157
+ // Models are auto-fetched at SDK initialization and saved to the registry
154
158
  try {
155
159
  const models = await ModelRegistry.getAllModels();
156
160
  logger.info(`Successfully fetched ${models.length} model assignments`);
@@ -181,7 +185,8 @@ export async function getModelsForCategory(
181
185
  }
182
186
 
183
187
  /**
184
- * Clear cached model assignments
188
+ * Clear cached model assignments.
189
+ * Resets local state; next fetch will get fresh data from the registry.
185
190
  */
186
191
  export async function clearModelAssignmentsCache(
187
192
  initState: { isCoreInitialized: boolean }
@@ -190,8 +195,6 @@ export async function clearModelAssignmentsCache(
190
195
  return;
191
196
  }
192
197
 
193
- // Cache clearing is handled by native commons
194
- // Reset local state if needed
195
198
  ModelRegistry.reset();
196
199
  }
197
200
 
@@ -44,7 +44,7 @@ export const APIEndpoints = {
44
44
  MODEL_INFO: '/api/v1/models',
45
45
 
46
46
  /** Model assignments */
47
- MODEL_ASSIGNMENTS: '/api/v1/model-assignments',
47
+ MODEL_ASSIGNMENTS: '/api/v1/model-assignments/for-sdk',
48
48
 
49
49
  /** Model assignments (development - Supabase) */
50
50
  DEV_MODEL_ASSIGNMENTS: '/rest/v1/sdk_model_assignments',