@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.
Files changed (106) hide show
  1. package/README.md +218 -2
  2. package/RunAnywhereCore.podspec +1 -0
  3. package/android/CMakeLists.txt +24 -2
  4. package/android/build.gradle +61 -9
  5. package/android/src/main/cpp/cpp-adapter.cpp +51 -3
  6. package/android/src/main/include/rac/backends/rac_vlm_llamacpp.h +216 -0
  7. package/android/src/main/include/rac/core/capabilities/rac_lifecycle.h +3 -1
  8. package/android/src/main/include/rac/core/rac_core.h +11 -0
  9. package/android/src/main/include/rac/core/rac_types.h +8 -6
  10. package/android/src/main/include/rac/features/diffusion/rac_diffusion.h +22 -0
  11. package/android/src/main/include/rac/features/diffusion/rac_diffusion_component.h +263 -0
  12. package/android/src/main/include/rac/features/diffusion/rac_diffusion_model_registry.h +358 -0
  13. package/android/src/main/include/rac/features/diffusion/rac_diffusion_service.h +187 -0
  14. package/android/src/main/include/rac/features/diffusion/rac_diffusion_tokenizer.h +167 -0
  15. package/android/src/main/include/rac/features/diffusion/rac_diffusion_types.h +454 -0
  16. package/android/src/main/include/rac/features/llm/rac_tool_calling.h +373 -0
  17. package/android/src/main/include/rac/features/platform/rac_diffusion_platform.h +305 -0
  18. package/android/src/main/include/rac/features/vad/rac_vad_energy.h +1 -1
  19. package/android/src/main/include/rac/features/vlm/rac_vlm.h +16 -0
  20. package/android/src/main/include/rac/features/vlm/rac_vlm_component.h +168 -0
  21. package/android/src/main/include/rac/features/vlm/rac_vlm_service.h +206 -0
  22. package/android/src/main/include/rac/features/vlm/rac_vlm_types.h +417 -0
  23. package/android/src/main/include/rac/infrastructure/model_management/rac_model_registry.h +15 -0
  24. package/android/src/main/include/rac/infrastructure/model_management/rac_model_types.h +3 -0
  25. package/android/src/main/include/rac/utils/rac_image_utils.h +215 -0
  26. package/android/src/main/java/com/margelo/nitro/runanywhere/PlatformAdapterBridge.kt +201 -1
  27. package/android/src/main/jniLibs/arm64-v8a/libc++_shared.so +0 -0
  28. package/android/src/main/jniLibs/arm64-v8a/libomp.so +0 -0
  29. package/android/src/main/jniLibs/arm64-v8a/librac_commons.so +0 -0
  30. package/android/src/main/jniLibs/arm64-v8a/librunanywhere_jni.so +0 -0
  31. package/android/src/main/jniLibs/x86_64/libc++_shared.so +0 -0
  32. package/android/src/main/jniLibs/x86_64/libomp.so +0 -0
  33. package/android/src/main/jniLibs/x86_64/librac_commons.so +0 -0
  34. package/android/src/main/jniLibs/x86_64/librunanywhere_jni.so +0 -0
  35. package/cpp/HybridRunAnywhereCore.cpp +263 -163
  36. package/cpp/HybridRunAnywhereCore.hpp +11 -0
  37. package/cpp/bridges/InitBridge.cpp +234 -3
  38. package/cpp/bridges/PlatformDownloadBridge.h +44 -0
  39. package/cpp/bridges/ToolCallingBridge.cpp +188 -0
  40. package/cpp/bridges/ToolCallingBridge.hpp +98 -0
  41. package/cpp/third_party/nlohmann/json.hpp +24765 -0
  42. package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/RACommons.h +18 -4
  43. package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_core.h +11 -0
  44. package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_diffusion.h +22 -0
  45. package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_diffusion_component.h +263 -0
  46. package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_diffusion_model_registry.h +358 -0
  47. package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_diffusion_platform.h +305 -0
  48. package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_diffusion_service.h +187 -0
  49. package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_diffusion_tokenizer.h +167 -0
  50. package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_diffusion_types.h +454 -0
  51. package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_endpoints.h +3 -17
  52. package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_image_utils.h +215 -0
  53. package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_lifecycle.h +3 -1
  54. package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_model_assignment.h +4 -20
  55. package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_model_registry.h +15 -0
  56. package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_model_types.h +3 -0
  57. package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_tool_calling.h +373 -0
  58. package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_types.h +8 -6
  59. package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_vad_energy.h +1 -1
  60. package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_vlm.h +16 -0
  61. package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_vlm_component.h +168 -0
  62. package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_vlm_llamacpp.h +216 -0
  63. package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_vlm_service.h +206 -0
  64. package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/Headers/rac_vlm_types.h +417 -0
  65. package/ios/Binaries/RACommons.xcframework/ios-arm64/RACommons.framework/RACommons +0 -0
  66. package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/RACommons.h +18 -4
  67. package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_core.h +11 -0
  68. package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_diffusion.h +22 -0
  69. package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_diffusion_component.h +263 -0
  70. package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_diffusion_model_registry.h +358 -0
  71. package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_diffusion_platform.h +305 -0
  72. package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_diffusion_service.h +187 -0
  73. package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_diffusion_tokenizer.h +167 -0
  74. package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_diffusion_types.h +454 -0
  75. package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_endpoints.h +3 -17
  76. package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_image_utils.h +215 -0
  77. package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_lifecycle.h +3 -1
  78. package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_model_assignment.h +4 -20
  79. package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_model_registry.h +15 -0
  80. package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_model_types.h +3 -0
  81. package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_tool_calling.h +373 -0
  82. package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_types.h +8 -6
  83. package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_vad_energy.h +1 -1
  84. package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_vlm.h +16 -0
  85. package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_vlm_component.h +168 -0
  86. package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_vlm_llamacpp.h +216 -0
  87. package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_vlm_service.h +206 -0
  88. package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers/rac_vlm_types.h +417 -0
  89. package/ios/Binaries/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/RACommons +0 -0
  90. package/ios/PlatformAdapterBridge.h +24 -1
  91. package/ios/PlatformAdapterBridge.m +243 -0
  92. package/nitrogen/generated/shared/c++/HybridRunAnywhereCoreSpec.cpp +4 -0
  93. package/nitrogen/generated/shared/c++/HybridRunAnywhereCoreSpec.hpp +4 -0
  94. package/package.json +8 -4
  95. package/src/Foundation/Security/SecureStorageService.ts +12 -6
  96. package/src/Public/Extensions/RunAnywhere+Models.ts +5 -3
  97. package/src/Public/Extensions/RunAnywhere+STT.ts +7 -2
  98. package/src/Public/Extensions/RunAnywhere+ToolCalling.ts +472 -0
  99. package/src/Public/Extensions/index.ts +16 -0
  100. package/src/Public/RunAnywhere.ts +18 -0
  101. package/src/index.ts +0 -1
  102. package/src/services/Network/index.ts +0 -1
  103. package/src/services/index.ts +0 -1
  104. package/src/specs/RunAnywhereCore.nitro.ts +72 -0
  105. package/src/types/ToolCallingTypes.ts +198 -0
  106. package/src/types/index.ts +13 -0
@@ -10,6 +10,14 @@
10
10
  package com.margelo.nitro.runanywhere
11
11
 
12
12
  import android.util.Log
13
+ import java.io.File
14
+ import java.io.FileOutputStream
15
+ import java.net.HttpURLConnection
16
+ import java.net.URL
17
+ import java.util.concurrent.ConcurrentHashMap
18
+ import java.util.concurrent.Executors
19
+ import java.util.concurrent.Future
20
+ import java.util.concurrent.atomic.AtomicBoolean
13
21
 
14
22
  /**
15
23
  * JNI bridge that C++ code calls for platform operations.
@@ -18,6 +26,33 @@ import android.util.Log
18
26
  object PlatformAdapterBridge {
19
27
  private const val TAG = "PlatformAdapterBridge"
20
28
 
29
+ private const val RAC_SUCCESS = 0
30
+ private const val RAC_ERROR_INVALID_PARAMETER = -106
31
+ private const val RAC_ERROR_DOWNLOAD_FAILED = -153
32
+ private const val RAC_ERROR_CANCELLED = -380
33
+
34
+ private data class HttpDownloadTask(
35
+ val taskId: String,
36
+ val url: String,
37
+ val destinationPath: String,
38
+ val cancelFlag: AtomicBoolean = AtomicBoolean(false),
39
+ ) {
40
+ @Volatile
41
+ var connection: HttpURLConnection? = null
42
+
43
+ @Volatile
44
+ var future: Future<*>? = null
45
+ }
46
+
47
+ private val httpDownloadTasks = ConcurrentHashMap<String, HttpDownloadTask>()
48
+
49
+ private val httpDownloadExecutor =
50
+ Executors.newCachedThreadPool { runnable ->
51
+ Thread(runnable, "runanywhere-http-download").apply {
52
+ isDaemon = true
53
+ }
54
+ }
55
+
21
56
  /**
22
57
  * Called from C++ to set a secure value
23
58
  */
@@ -156,6 +191,172 @@ object PlatformAdapterBridge {
156
191
  }
157
192
  }
158
193
 
194
+ // ========================================================================
195
+ // HTTP Download (Async, Platform Adapter)
196
+ // ========================================================================
197
+
198
+ /**
199
+ * Start an HTTP download (async).
200
+ * Called from C++ platform adapter with a provided taskId.
201
+ */
202
+ @JvmStatic
203
+ fun httpDownload(url: String, destinationPath: String, taskId: String): Int {
204
+ if (url.isBlank() || destinationPath.isBlank() || taskId.isBlank()) {
205
+ Log.e(TAG, "httpDownload invalid args (taskId=$taskId)")
206
+ return RAC_ERROR_INVALID_PARAMETER
207
+ }
208
+
209
+ val task = HttpDownloadTask(taskId = taskId, url = url, destinationPath = destinationPath)
210
+ if (httpDownloadTasks.putIfAbsent(taskId, task) != null) {
211
+ Log.w(TAG, "httpDownload duplicate taskId=$taskId")
212
+ return RAC_ERROR_INVALID_PARAMETER
213
+ }
214
+
215
+ return try {
216
+ val future = httpDownloadExecutor.submit {
217
+ performHttpDownload(task)
218
+ }
219
+ task.future = future
220
+ RAC_SUCCESS
221
+ } catch (e: Exception) {
222
+ httpDownloadTasks.remove(taskId)
223
+ Log.e(TAG, "httpDownload schedule failed: ${e.message}")
224
+ RAC_ERROR_DOWNLOAD_FAILED
225
+ }
226
+ }
227
+
228
+ /**
229
+ * Cancel an HTTP download.
230
+ */
231
+ @JvmStatic
232
+ fun httpDownloadCancel(taskId: String): Boolean {
233
+ val task = httpDownloadTasks[taskId] ?: return false
234
+ task.cancelFlag.set(true)
235
+ task.connection?.disconnect()
236
+ return true
237
+ }
238
+
239
+ private fun performHttpDownload(task: HttpDownloadTask) {
240
+ var result = RAC_ERROR_DOWNLOAD_FAILED
241
+ var finalPath: String? = null
242
+ var tempFile: File? = null
243
+
244
+ try {
245
+ if (task.cancelFlag.get()) {
246
+ result = RAC_ERROR_CANCELLED
247
+ return
248
+ }
249
+
250
+ val connection = URL(task.url).openConnection() as HttpURLConnection
251
+ task.connection = connection
252
+ connection.instanceFollowRedirects = true
253
+ connection.connectTimeout = 30_000
254
+ connection.readTimeout = 60_000
255
+ connection.requestMethod = "GET"
256
+ connection.connect()
257
+
258
+ val status = connection.responseCode
259
+ if (status !in 200..299) {
260
+ Log.e(TAG, "httpDownload failed status=$status url=${task.url}")
261
+ result = RAC_ERROR_DOWNLOAD_FAILED
262
+ return
263
+ }
264
+
265
+ val totalBytes = connection.contentLengthLong.let { if (it > 0) it else 0L }
266
+ val destFile = File(task.destinationPath)
267
+ val parentDir = destFile.parentFile
268
+ parentDir?.mkdirs()
269
+ val temp = if (parentDir != null) {
270
+ File(parentDir, destFile.name + ".part")
271
+ } else {
272
+ File(destFile.path + ".part")
273
+ }
274
+ tempFile = temp
275
+ if (temp.exists()) {
276
+ temp.delete()
277
+ }
278
+
279
+ var downloaded = 0L
280
+ var lastReported = 0L
281
+ val reportThreshold = 256 * 1024L
282
+
283
+ connection.inputStream.use { input ->
284
+ FileOutputStream(temp).use { output ->
285
+ val buffer = ByteArray(8192)
286
+ while (true) {
287
+ if (task.cancelFlag.get()) {
288
+ result = RAC_ERROR_CANCELLED
289
+ return
290
+ }
291
+ val read = input.read(buffer)
292
+ if (read <= 0) break
293
+ output.write(buffer, 0, read)
294
+ downloaded += read
295
+ if (downloaded - lastReported >= reportThreshold) {
296
+ nativeHttpDownloadReportProgress(task.taskId, downloaded, totalBytes)
297
+ lastReported = downloaded
298
+ }
299
+ }
300
+ }
301
+ }
302
+
303
+ if (task.cancelFlag.get()) {
304
+ result = RAC_ERROR_CANCELLED
305
+ return
306
+ }
307
+
308
+ if (temp.exists()) {
309
+ if (destFile.exists()) {
310
+ destFile.delete()
311
+ }
312
+ val moved = temp.renameTo(destFile)
313
+ if (!moved) {
314
+ temp.copyTo(destFile, overwrite = true)
315
+ temp.delete()
316
+ }
317
+ }
318
+
319
+ nativeHttpDownloadReportProgress(task.taskId, downloaded, totalBytes)
320
+ finalPath = destFile.absolutePath
321
+ result = RAC_SUCCESS
322
+ } catch (e: Exception) {
323
+ result = if (task.cancelFlag.get()) {
324
+ RAC_ERROR_CANCELLED
325
+ } else {
326
+ Log.e(TAG, "httpDownload failed for ${task.url}: ${e.message}")
327
+ RAC_ERROR_DOWNLOAD_FAILED
328
+ }
329
+ } finally {
330
+ task.connection?.disconnect()
331
+ task.connection = null
332
+ httpDownloadTasks.remove(task.taskId)
333
+
334
+ if (result != RAC_SUCCESS) {
335
+ tempFile?.let {
336
+ if (it.exists()) {
337
+ it.delete()
338
+ }
339
+ }
340
+ }
341
+
342
+ nativeHttpDownloadReportComplete(task.taskId, result, finalPath)
343
+ }
344
+ }
345
+
346
+ @JvmStatic
347
+ private external fun nativeHttpDownloadReportProgress(
348
+ taskId: String,
349
+ downloadedBytes: Long,
350
+ totalBytes: Long,
351
+ ): Int
352
+
353
+ @JvmStatic
354
+ private external fun nativeHttpDownloadReportComplete(
355
+ taskId: String,
356
+ result: Int,
357
+ downloadedPath: String?,
358
+ ): Int
359
+
159
360
  // ========================================================================
160
361
  // Device Info (Synchronous)
161
362
  // For device registration callback which must be synchronous
@@ -389,4 +590,3 @@ object PlatformAdapterBridge {
389
590
  return false
390
591
  }
391
592
  }
392
-