@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
@@ -0,0 +1,216 @@
1
+ /**
2
+ * @file rac_vlm_llamacpp.h
3
+ * @brief RunAnywhere Commons - LlamaCPP VLM Backend API
4
+ *
5
+ * Public C API for Vision Language Model inference using llama.cpp's
6
+ * multimodal (mtmd) capabilities. Supports 20+ VLM architectures including
7
+ * Qwen2-VL, Qwen2.5-VL, SmolVLM, LLaVA, MiniCPM-V, and more.
8
+ */
9
+
10
+ #ifndef RAC_VLM_LLAMACPP_H
11
+ #define RAC_VLM_LLAMACPP_H
12
+
13
+ #include "rac/core/rac_error.h"
14
+ #include "rac/core/rac_types.h"
15
+ #include "rac/features/vlm/rac_vlm.h"
16
+
17
+ #ifdef __cplusplus
18
+ extern "C" {
19
+ #endif
20
+
21
+ // =============================================================================
22
+ // EXPORT MACRO
23
+ // =============================================================================
24
+
25
+ #if defined(RAC_LLAMACPP_BUILDING)
26
+ #if defined(_WIN32)
27
+ #define RAC_LLAMACPP_VLM_API __declspec(dllexport)
28
+ #elif defined(__GNUC__) || defined(__clang__)
29
+ #define RAC_LLAMACPP_VLM_API __attribute__((visibility("default")))
30
+ #else
31
+ #define RAC_LLAMACPP_VLM_API
32
+ #endif
33
+ #else
34
+ #define RAC_LLAMACPP_VLM_API
35
+ #endif
36
+
37
+ // =============================================================================
38
+ // CONFIGURATION
39
+ // =============================================================================
40
+
41
+ /**
42
+ * LlamaCPP VLM-specific configuration.
43
+ */
44
+ typedef struct rac_vlm_llamacpp_config {
45
+ /** Context size (0 = auto-detect from model) */
46
+ int32_t context_size;
47
+
48
+ /** Number of threads for CPU inference (0 = auto-detect) */
49
+ int32_t num_threads;
50
+
51
+ /** Number of layers to offload to GPU (Metal on iOS/macOS, -1 = all) */
52
+ int32_t gpu_layers;
53
+
54
+ /** Batch size for prompt processing */
55
+ int32_t batch_size;
56
+
57
+ /** Number of threads for vision encoder (0 = same as num_threads) */
58
+ int32_t vision_threads;
59
+
60
+ /** Use GPU for vision encoding */
61
+ rac_bool_t use_gpu_vision;
62
+ } rac_vlm_llamacpp_config_t;
63
+
64
+ /**
65
+ * Default LlamaCPP VLM configuration.
66
+ */
67
+ static const rac_vlm_llamacpp_config_t RAC_VLM_LLAMACPP_CONFIG_DEFAULT = {
68
+ .context_size = 0, // Auto-detect
69
+ .num_threads = 0, // Auto-detect
70
+ .gpu_layers = -1, // All layers on GPU
71
+ .batch_size = 512, //
72
+ .vision_threads = 0, // Auto-detect
73
+ .use_gpu_vision = 1 // Use GPU for vision
74
+ };
75
+
76
+ // =============================================================================
77
+ // LLAMACPP VLM-SPECIFIC API
78
+ // =============================================================================
79
+
80
+ /**
81
+ * Creates a LlamaCPP VLM service.
82
+ *
83
+ * @param model_path Path to the GGUF LLM model file
84
+ * @param mmproj_path Path to the mmproj vision projector GGUF file
85
+ * @param config LlamaCPP-specific configuration (can be NULL for defaults)
86
+ * @param out_handle Output: Handle to the created service
87
+ * @return RAC_SUCCESS or error code
88
+ */
89
+ RAC_LLAMACPP_VLM_API rac_result_t rac_vlm_llamacpp_create(const char* model_path,
90
+ const char* mmproj_path,
91
+ const rac_vlm_llamacpp_config_t* config,
92
+ rac_handle_t* out_handle);
93
+
94
+ /**
95
+ * Loads a VLM model into an existing service.
96
+ *
97
+ * @param handle Service handle
98
+ * @param model_path Path to the GGUF LLM model file
99
+ * @param mmproj_path Path to the mmproj vision projector GGUF file
100
+ * @param config LlamaCPP configuration (can be NULL)
101
+ * @return RAC_SUCCESS or error code
102
+ */
103
+ RAC_LLAMACPP_VLM_API rac_result_t rac_vlm_llamacpp_load_model(
104
+ rac_handle_t handle, const char* model_path, const char* mmproj_path,
105
+ const rac_vlm_llamacpp_config_t* config);
106
+
107
+ /**
108
+ * Unloads the current model.
109
+ *
110
+ * @param handle Service handle
111
+ * @return RAC_SUCCESS or error code
112
+ */
113
+ RAC_LLAMACPP_VLM_API rac_result_t rac_vlm_llamacpp_unload_model(rac_handle_t handle);
114
+
115
+ /**
116
+ * Checks if a model is loaded.
117
+ *
118
+ * @param handle Service handle
119
+ * @return RAC_TRUE if model is loaded, RAC_FALSE otherwise
120
+ */
121
+ RAC_LLAMACPP_VLM_API rac_bool_t rac_vlm_llamacpp_is_model_loaded(rac_handle_t handle);
122
+
123
+ /**
124
+ * Processes an image with a text prompt (blocking).
125
+ *
126
+ * @param handle Service handle
127
+ * @param image Image input (file path, RGB pixels, or base64)
128
+ * @param prompt Text prompt
129
+ * @param options VLM generation options (can be NULL for defaults)
130
+ * @param out_result Output: Generation result (caller must free text with rac_free)
131
+ * @return RAC_SUCCESS or error code
132
+ */
133
+ RAC_LLAMACPP_VLM_API rac_result_t rac_vlm_llamacpp_process(rac_handle_t handle,
134
+ const rac_vlm_image_t* image,
135
+ const char* prompt,
136
+ const rac_vlm_options_t* options,
137
+ rac_vlm_result_t* out_result);
138
+
139
+ /**
140
+ * Streaming callback for VLM generation.
141
+ *
142
+ * @param token Generated token string
143
+ * @param is_final Whether this is the final token
144
+ * @param user_data User-provided context
145
+ * @return RAC_TRUE to continue, RAC_FALSE to stop
146
+ */
147
+ typedef rac_bool_t (*rac_vlm_llamacpp_stream_callback_fn)(const char* token, rac_bool_t is_final,
148
+ void* user_data);
149
+
150
+ /**
151
+ * Processes an image with streaming callback.
152
+ *
153
+ * @param handle Service handle
154
+ * @param image Image input
155
+ * @param prompt Text prompt
156
+ * @param options VLM generation options
157
+ * @param callback Callback for each token
158
+ * @param user_data User context passed to callback
159
+ * @return RAC_SUCCESS or error code
160
+ */
161
+ RAC_LLAMACPP_VLM_API rac_result_t rac_vlm_llamacpp_process_stream(
162
+ rac_handle_t handle, const rac_vlm_image_t* image, const char* prompt,
163
+ const rac_vlm_options_t* options, rac_vlm_llamacpp_stream_callback_fn callback, void* user_data);
164
+
165
+ /**
166
+ * Cancels ongoing generation.
167
+ *
168
+ * @param handle Service handle
169
+ */
170
+ RAC_LLAMACPP_VLM_API void rac_vlm_llamacpp_cancel(rac_handle_t handle);
171
+
172
+ /**
173
+ * Gets model information as JSON.
174
+ *
175
+ * @param handle Service handle
176
+ * @param out_json Output: JSON string (caller must free with rac_free)
177
+ * @return RAC_SUCCESS or error code
178
+ */
179
+ RAC_LLAMACPP_VLM_API rac_result_t rac_vlm_llamacpp_get_model_info(rac_handle_t handle,
180
+ char** out_json);
181
+
182
+ /**
183
+ * Destroys a LlamaCPP VLM service.
184
+ *
185
+ * @param handle Service handle to destroy
186
+ */
187
+ RAC_LLAMACPP_VLM_API void rac_vlm_llamacpp_destroy(rac_handle_t handle);
188
+
189
+ // =============================================================================
190
+ // BACKEND REGISTRATION
191
+ // =============================================================================
192
+
193
+ /**
194
+ * Registers the LlamaCPP VLM backend with the commons module and service registries.
195
+ *
196
+ * Should be called once during SDK initialization.
197
+ * This registers:
198
+ * - Module: "llamacpp_vlm" with VISION_LANGUAGE capability
199
+ * - Service provider: LlamaCPP VLM provider (priority 100)
200
+ *
201
+ * @return RAC_SUCCESS or error code
202
+ */
203
+ RAC_LLAMACPP_VLM_API rac_result_t rac_backend_llamacpp_vlm_register(void);
204
+
205
+ /**
206
+ * Unregisters the LlamaCPP VLM backend.
207
+ *
208
+ * @return RAC_SUCCESS or error code
209
+ */
210
+ RAC_LLAMACPP_VLM_API rac_result_t rac_backend_llamacpp_vlm_unregister(void);
211
+
212
+ #ifdef __cplusplus
213
+ }
214
+ #endif
215
+
216
+ #endif /* RAC_VLM_LLAMACPP_H */
@@ -45,7 +45,9 @@ typedef enum rac_resource_type {
45
45
  RAC_RESOURCE_TYPE_STT_MODEL = 1,
46
46
  RAC_RESOURCE_TYPE_TTS_VOICE = 2,
47
47
  RAC_RESOURCE_TYPE_VAD_MODEL = 3,
48
- RAC_RESOURCE_TYPE_DIARIZATION_MODEL = 4
48
+ RAC_RESOURCE_TYPE_DIARIZATION_MODEL = 4,
49
+ RAC_RESOURCE_TYPE_VLM_MODEL = 5, /**< Vision Language Model */
50
+ RAC_RESOURCE_TYPE_DIFFUSION_MODEL = 6 /**< Diffusion/Image Generation Model */
49
51
  } rac_resource_type_t;
50
52
 
51
53
  /**
@@ -324,6 +324,17 @@ RAC_API rac_result_t rac_register_model(const struct rac_model_info* model);
324
324
  */
325
325
  RAC_API rac_result_t rac_get_model(const char* model_id, struct rac_model_info** out_model);
326
326
 
327
+ /**
328
+ * Gets model info from the global registry by local path.
329
+ * Convenience function that calls rac_model_registry_get_by_path on the global registry.
330
+ * Useful when loading models by path instead of model_id.
331
+ *
332
+ * @param local_path Local path to search for
333
+ * @param out_model Output: Model info (owned, must be freed with rac_model_info_free)
334
+ * @return RAC_SUCCESS on success, RAC_ERROR_NOT_FOUND if not registered
335
+ */
336
+ RAC_API rac_result_t rac_get_model_by_path(const char* local_path, struct rac_model_info** out_model);
337
+
327
338
  #ifdef __cplusplus
328
339
  }
329
340
  #endif
@@ -166,12 +166,14 @@ typedef struct rac_memory_info {
166
166
  */
167
167
  typedef enum rac_capability {
168
168
  RAC_CAPABILITY_UNKNOWN = 0,
169
- RAC_CAPABILITY_TEXT_GENERATION = 1, /**< LLM text generation */
170
- RAC_CAPABILITY_EMBEDDINGS = 2, /**< Text embeddings */
171
- RAC_CAPABILITY_STT = 3, /**< Speech-to-text */
172
- RAC_CAPABILITY_TTS = 4, /**< Text-to-speech */
173
- RAC_CAPABILITY_VAD = 5, /**< Voice activity detection */
174
- RAC_CAPABILITY_DIARIZATION = 6, /**< Speaker diarization */
169
+ RAC_CAPABILITY_TEXT_GENERATION = 1, /**< LLM text generation */
170
+ RAC_CAPABILITY_EMBEDDINGS = 2, /**< Text embeddings */
171
+ RAC_CAPABILITY_STT = 3, /**< Speech-to-text */
172
+ RAC_CAPABILITY_TTS = 4, /**< Text-to-speech */
173
+ RAC_CAPABILITY_VAD = 5, /**< Voice activity detection */
174
+ RAC_CAPABILITY_DIARIZATION = 6, /**< Speaker diarization */
175
+ RAC_CAPABILITY_VISION_LANGUAGE = 7, /**< Vision-language model (VLM) */
176
+ RAC_CAPABILITY_DIFFUSION = 8, /**< Image generation (Stable Diffusion) */
175
177
  } rac_capability_t;
176
178
 
177
179
  /**
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @file rac_diffusion.h
3
+ * @brief RunAnywhere Commons - Diffusion Feature Umbrella Header
4
+ *
5
+ * Include this header to use diffusion (image generation) capabilities.
6
+ * This provides text-to-image, image-to-image, and inpainting using
7
+ * Stable Diffusion models.
8
+ *
9
+ * Supported backends:
10
+ * - CoreML (Apple platforms) - via Platform backend
11
+ * - ONNX Runtime (cross-platform) - via ONNX backend
12
+ */
13
+
14
+ #ifndef RAC_DIFFUSION_H
15
+ #define RAC_DIFFUSION_H
16
+
17
+ #include "rac/features/diffusion/rac_diffusion_component.h"
18
+ #include "rac/features/diffusion/rac_diffusion_service.h"
19
+ #include "rac/features/diffusion/rac_diffusion_tokenizer.h"
20
+ #include "rac/features/diffusion/rac_diffusion_types.h"
21
+
22
+ #endif /* RAC_DIFFUSION_H */
@@ -0,0 +1,263 @@
1
+ /**
2
+ * @file rac_diffusion_component.h
3
+ * @brief RunAnywhere Commons - Diffusion Capability Component
4
+ *
5
+ * Actor-based diffusion capability that owns model lifecycle and generation.
6
+ * Uses lifecycle manager for unified lifecycle + analytics handling.
7
+ *
8
+ * Supports:
9
+ * - Text-to-image generation
10
+ * - Image-to-image transformation
11
+ * - Inpainting with mask
12
+ * - Progress reporting with optional intermediate images
13
+ */
14
+
15
+ #ifndef RAC_DIFFUSION_COMPONENT_H
16
+ #define RAC_DIFFUSION_COMPONENT_H
17
+
18
+ #include "rac/core/capabilities/rac_lifecycle.h"
19
+ #include "rac/core/rac_error.h"
20
+ #include "rac/features/diffusion/rac_diffusion_types.h"
21
+
22
+ #ifdef __cplusplus
23
+ extern "C" {
24
+ #endif
25
+
26
+ // =============================================================================
27
+ // DIFFUSION COMPONENT API - Component lifecycle and generation
28
+ // =============================================================================
29
+
30
+ /**
31
+ * @brief Create a diffusion capability component
32
+ *
33
+ * @param out_handle Output: Handle to the component
34
+ * @return RAC_SUCCESS or error code
35
+ */
36
+ RAC_API rac_result_t rac_diffusion_component_create(rac_handle_t* out_handle);
37
+
38
+ /**
39
+ * @brief Configure the diffusion component
40
+ *
41
+ * @param handle Component handle
42
+ * @param config Configuration
43
+ * @return RAC_SUCCESS or error code
44
+ */
45
+ RAC_API rac_result_t rac_diffusion_component_configure(rac_handle_t handle,
46
+ const rac_diffusion_config_t* config);
47
+
48
+ /**
49
+ * @brief Check if model is loaded
50
+ *
51
+ * @param handle Component handle
52
+ * @return RAC_TRUE if loaded, RAC_FALSE otherwise
53
+ */
54
+ RAC_API rac_bool_t rac_diffusion_component_is_loaded(rac_handle_t handle);
55
+
56
+ /**
57
+ * @brief Get current model ID
58
+ *
59
+ * @param handle Component handle
60
+ * @return Current model ID (NULL if not loaded)
61
+ */
62
+ RAC_API const char* rac_diffusion_component_get_model_id(rac_handle_t handle);
63
+
64
+ /**
65
+ * @brief Load a diffusion model
66
+ *
67
+ * @param handle Component handle
68
+ * @param model_path Path to the model directory
69
+ * @param model_id Model identifier for telemetry
70
+ * @param model_name Human-readable model name
71
+ * @return RAC_SUCCESS or error code
72
+ */
73
+ RAC_API rac_result_t rac_diffusion_component_load_model(rac_handle_t handle, const char* model_path,
74
+ const char* model_id,
75
+ const char* model_name);
76
+
77
+ /**
78
+ * @brief Unload the current model
79
+ *
80
+ * @param handle Component handle
81
+ * @return RAC_SUCCESS or error code
82
+ */
83
+ RAC_API rac_result_t rac_diffusion_component_unload(rac_handle_t handle);
84
+
85
+ /**
86
+ * @brief Cleanup and reset the component
87
+ *
88
+ * @param handle Component handle
89
+ * @return RAC_SUCCESS or error code
90
+ */
91
+ RAC_API rac_result_t rac_diffusion_component_cleanup(rac_handle_t handle);
92
+
93
+ /**
94
+ * @brief Cancel ongoing generation
95
+ *
96
+ * Best-effort cancellation.
97
+ *
98
+ * @param handle Component handle
99
+ * @return RAC_SUCCESS or error code
100
+ */
101
+ RAC_API rac_result_t rac_diffusion_component_cancel(rac_handle_t handle);
102
+
103
+ /**
104
+ * @brief Generate an image (non-streaming)
105
+ *
106
+ * Blocking call that generates an image from the prompt.
107
+ *
108
+ * @param handle Component handle
109
+ * @param options Generation options
110
+ * @param out_result Output: Generation result
111
+ * @return RAC_SUCCESS or error code
112
+ */
113
+ RAC_API rac_result_t rac_diffusion_component_generate(rac_handle_t handle,
114
+ const rac_diffusion_options_t* options,
115
+ rac_diffusion_result_t* out_result);
116
+
117
+ /**
118
+ * @brief Generate an image with progress callbacks
119
+ *
120
+ * Non-blocking call with progress reporting via callbacks.
121
+ *
122
+ * @param handle Component handle
123
+ * @param options Generation options
124
+ * @param progress_callback Called for each progress update
125
+ * @param complete_callback Called when generation completes
126
+ * @param error_callback Called on error
127
+ * @param user_data User context passed to callbacks
128
+ * @return RAC_SUCCESS or error code
129
+ */
130
+ RAC_API rac_result_t rac_diffusion_component_generate_with_callbacks(
131
+ rac_handle_t handle, const rac_diffusion_options_t* options,
132
+ rac_diffusion_progress_callback_fn progress_callback,
133
+ rac_diffusion_complete_callback_fn complete_callback,
134
+ rac_diffusion_error_callback_fn error_callback, void* user_data);
135
+
136
+ // =============================================================================
137
+ // JSON CONVENIENCE HELPERS
138
+ // =============================================================================
139
+
140
+ /**
141
+ * @brief Configure diffusion component from JSON
142
+ *
143
+ * JSON schema (flat object):
144
+ * {
145
+ * "model_id": "optional-model-id",
146
+ * "model_variant": 0 | "sd15" | "sd21" | "sdxl" | "sdxl_turbo" | "sdxs" | "lcm",
147
+ * "enable_safety_checker": true/false,
148
+ * "reduce_memory": true/false,
149
+ * "tokenizer_source": 0 | 1 | 2 | 99,
150
+ * "tokenizer_custom_url": "https://..."
151
+ * }
152
+ *
153
+ * @param handle Component handle
154
+ * @param config_json JSON string
155
+ * @return RAC_SUCCESS or error code
156
+ */
157
+ RAC_API rac_result_t rac_diffusion_component_configure_json(rac_handle_t handle,
158
+ const char* config_json);
159
+
160
+ /**
161
+ * @brief Generate image from JSON options
162
+ *
163
+ * JSON schema (flat object):
164
+ * {
165
+ * "prompt": "text prompt",
166
+ * "negative_prompt": "optional",
167
+ * "width": 512,
168
+ * "height": 512,
169
+ * "steps": 28,
170
+ * "guidance_scale": 7.5,
171
+ * "seed": -1,
172
+ * "scheduler": 0 | "dpm++_2m_karras" | "dpm++_2m" | "dpm++_2m_sde" | "ddim" | "euler" | "euler_a" | "pndm" | "lms",
173
+ * "mode": 0 | "txt2img" | "img2img" | "inpainting",
174
+ * "denoise_strength": 0.75,
175
+ * "report_intermediate_images": false,
176
+ * "progress_stride": 1
177
+ * }
178
+ *
179
+ * @param handle Component handle
180
+ * @param options_json JSON string
181
+ * @param input_image_data Optional input image bytes (PNG/JPEG or RGBA)
182
+ * @param input_image_size Size of input image bytes
183
+ * @param mask_data Optional mask image bytes (PNG/JPEG or grayscale)
184
+ * @param mask_size Size of mask bytes
185
+ * @param out_json Output JSON (caller must free with rac_free)
186
+ * @return RAC_SUCCESS or error code
187
+ */
188
+ RAC_API rac_result_t rac_diffusion_component_generate_json(
189
+ rac_handle_t handle, const char* options_json, const uint8_t* input_image_data,
190
+ size_t input_image_size, const uint8_t* mask_data, size_t mask_size, char** out_json);
191
+
192
+ /**
193
+ * @brief Get diffusion info as JSON
194
+ *
195
+ * Output schema:
196
+ * {
197
+ * "is_ready": true/false,
198
+ * "current_model": "id",
199
+ * "model_variant": 0,
200
+ * "supports_text_to_image": true/false,
201
+ * "supports_image_to_image": true/false,
202
+ * "supports_inpainting": true/false,
203
+ * "safety_checker_enabled": true/false,
204
+ * "max_width": 512,
205
+ * "max_height": 512
206
+ * }
207
+ *
208
+ * @param handle Component handle
209
+ * @param out_json Output JSON (caller must free with rac_free)
210
+ * @return RAC_SUCCESS or error code
211
+ */
212
+ RAC_API rac_result_t rac_diffusion_component_get_info_json(rac_handle_t handle, char** out_json);
213
+
214
+ /**
215
+ * @brief Get supported capabilities
216
+ *
217
+ * Returns a bitmask of supported capabilities.
218
+ *
219
+ * @param handle Component handle
220
+ * @return Capability bitmask (RAC_DIFFUSION_CAP_* flags)
221
+ */
222
+ RAC_API uint32_t rac_diffusion_component_get_capabilities(rac_handle_t handle);
223
+
224
+ /**
225
+ * @brief Get service information
226
+ *
227
+ * @param handle Component handle
228
+ * @param out_info Output: Service information
229
+ * @return RAC_SUCCESS or error code
230
+ */
231
+ RAC_API rac_result_t rac_diffusion_component_get_info(rac_handle_t handle,
232
+ rac_diffusion_info_t* out_info);
233
+
234
+ /**
235
+ * @brief Get lifecycle state
236
+ *
237
+ * @param handle Component handle
238
+ * @return Current lifecycle state
239
+ */
240
+ RAC_API rac_lifecycle_state_t rac_diffusion_component_get_state(rac_handle_t handle);
241
+
242
+ /**
243
+ * @brief Get lifecycle metrics
244
+ *
245
+ * @param handle Component handle
246
+ * @param out_metrics Output: Lifecycle metrics
247
+ * @return RAC_SUCCESS or error code
248
+ */
249
+ RAC_API rac_result_t rac_diffusion_component_get_metrics(rac_handle_t handle,
250
+ rac_lifecycle_metrics_t* out_metrics);
251
+
252
+ /**
253
+ * @brief Destroy the diffusion component
254
+ *
255
+ * @param handle Component handle
256
+ */
257
+ RAC_API void rac_diffusion_component_destroy(rac_handle_t handle);
258
+
259
+ #ifdef __cplusplus
260
+ }
261
+ #endif
262
+
263
+ #endif /* RAC_DIFFUSION_COMPONENT_H */