@runanywhere/core 0.17.8 → 0.18.1
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
|
@@ -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
|
/**
|
|
@@ -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
|
|
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
|
// =============================================================================
|
|
@@ -86,6 +86,21 @@ RAC_API rac_result_t rac_model_registry_save(rac_model_registry_handle_t handle,
|
|
|
86
86
|
RAC_API rac_result_t rac_model_registry_get(rac_model_registry_handle_t handle,
|
|
87
87
|
const char* model_id, rac_model_info_t** out_model);
|
|
88
88
|
|
|
89
|
+
/**
|
|
90
|
+
* @brief Get model metadata by local path.
|
|
91
|
+
*
|
|
92
|
+
* Searches through all registered models and returns the one with matching local_path.
|
|
93
|
+
* This is useful when loading models by path instead of model_id.
|
|
94
|
+
*
|
|
95
|
+
* @param handle Registry handle
|
|
96
|
+
* @param local_path Local path to search for
|
|
97
|
+
* @param out_model Output: Model info (owned, must be freed with rac_model_info_free)
|
|
98
|
+
* @return RAC_SUCCESS, RAC_ERROR_NOT_FOUND, or other error code
|
|
99
|
+
*/
|
|
100
|
+
RAC_API rac_result_t rac_model_registry_get_by_path(rac_model_registry_handle_t handle,
|
|
101
|
+
const char* local_path,
|
|
102
|
+
rac_model_info_t** out_model);
|
|
103
|
+
|
|
89
104
|
/**
|
|
90
105
|
* @brief Load all stored models.
|
|
91
106
|
*
|
|
@@ -163,6 +163,7 @@ typedef enum rac_model_format {
|
|
|
163
163
|
RAC_MODEL_FORMAT_ORT = 1, /**< ONNX Runtime format */
|
|
164
164
|
RAC_MODEL_FORMAT_GGUF = 2, /**< GGUF format (llama.cpp) */
|
|
165
165
|
RAC_MODEL_FORMAT_BIN = 3, /**< Binary format */
|
|
166
|
+
RAC_MODEL_FORMAT_COREML = 4, /**< Core ML format (.mlmodelc, .mlpackage) */
|
|
166
167
|
RAC_MODEL_FORMAT_UNKNOWN = 99 /**< Unknown format */
|
|
167
168
|
} rac_model_format_t;
|
|
168
169
|
|
|
@@ -182,6 +183,8 @@ typedef enum rac_inference_framework {
|
|
|
182
183
|
RAC_FRAMEWORK_FLUID_AUDIO = 4, /**< FluidAudio */
|
|
183
184
|
RAC_FRAMEWORK_BUILTIN = 5, /**< Built-in (e.g., energy VAD) */
|
|
184
185
|
RAC_FRAMEWORK_NONE = 6, /**< No framework needed */
|
|
186
|
+
RAC_FRAMEWORK_MLX = 7, /**< MLX C++ (Apple Silicon VLM) */
|
|
187
|
+
RAC_FRAMEWORK_COREML = 8, /**< Core ML (Apple Neural Engine) */
|
|
185
188
|
RAC_FRAMEWORK_UNKNOWN = 99 /**< Unknown framework */
|
|
186
189
|
} rac_inference_framework_t;
|
|
187
190
|
|
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file rac_tool_calling.h
|
|
3
|
+
* @brief RunAnywhere Commons - Tool Calling API
|
|
4
|
+
*
|
|
5
|
+
* *** SINGLE SOURCE OF TRUTH FOR ALL TOOL CALLING LOGIC ***
|
|
6
|
+
*
|
|
7
|
+
* This header provides ALL tool calling functionality. Platform SDKs should
|
|
8
|
+
* ONLY call these functions - no fallback implementations allowed.
|
|
9
|
+
*
|
|
10
|
+
* Architecture:
|
|
11
|
+
* - C++ handles: ALL parsing, prompt formatting, JSON handling, follow-up prompts
|
|
12
|
+
* - Platform SDKs handle ONLY: tool registry (closures), tool execution (needs platform APIs)
|
|
13
|
+
*
|
|
14
|
+
* Supported Tool Calling Formats:
|
|
15
|
+
* - DEFAULT: <tool_call>{"tool":"name","arguments":{}}</tool_call> (Most general models)
|
|
16
|
+
* - LFM2: <|tool_call_start|>[func(arg="val")]<|tool_call_end|> (Liquid AI models)
|
|
17
|
+
*
|
|
18
|
+
* Ported from:
|
|
19
|
+
* - Swift: ToolCallParser.swift
|
|
20
|
+
* - React Native: ToolCallingBridge.cpp
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
#ifndef RAC_TOOL_CALLING_H
|
|
24
|
+
#define RAC_TOOL_CALLING_H
|
|
25
|
+
|
|
26
|
+
#include <RACommons/rac_error.h>
|
|
27
|
+
#include <RACommons/rac_types.h>
|
|
28
|
+
|
|
29
|
+
#ifdef __cplusplus
|
|
30
|
+
extern "C" {
|
|
31
|
+
#endif
|
|
32
|
+
|
|
33
|
+
// =============================================================================
|
|
34
|
+
// TOOL CALLING FORMATS - Different models use different formats
|
|
35
|
+
// =============================================================================
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @brief Tool calling format identifiers
|
|
39
|
+
*
|
|
40
|
+
* Different LLM models use different tool calling formats. This enum allows
|
|
41
|
+
* specifying which format to use for parsing and prompt generation.
|
|
42
|
+
*/
|
|
43
|
+
typedef enum rac_tool_call_format {
|
|
44
|
+
/**
|
|
45
|
+
* @brief SDK Default format: <tool_call>JSON</tool_call>
|
|
46
|
+
*
|
|
47
|
+
* Format: <tool_call>{"tool": "name", "arguments": {...}}</tool_call>
|
|
48
|
+
* Used by: Most general-purpose models (Llama, Qwen, Mistral, etc.)
|
|
49
|
+
*/
|
|
50
|
+
RAC_TOOL_FORMAT_DEFAULT = 0,
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @brief Liquid AI LFM2-Tool format
|
|
54
|
+
*
|
|
55
|
+
* Format: <|tool_call_start|>[func_name(arg1="val1", arg2="val2")]<|tool_call_end|>
|
|
56
|
+
* Used by: LiquidAI/LFM2-1.2B-Tool, LiquidAI/LFM2-350M-Tool
|
|
57
|
+
* Note: Uses Pythonic function call syntax
|
|
58
|
+
*/
|
|
59
|
+
RAC_TOOL_FORMAT_LFM2 = 1,
|
|
60
|
+
|
|
61
|
+
/** Number of formats (for iteration) */
|
|
62
|
+
RAC_TOOL_FORMAT_COUNT
|
|
63
|
+
} rac_tool_call_format_t;
|
|
64
|
+
|
|
65
|
+
// =============================================================================
|
|
66
|
+
// TYPES - Canonical definitions used by all SDKs
|
|
67
|
+
// =============================================================================
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @brief Parameter types for tool arguments
|
|
71
|
+
*/
|
|
72
|
+
typedef enum rac_tool_param_type {
|
|
73
|
+
RAC_TOOL_PARAM_STRING = 0,
|
|
74
|
+
RAC_TOOL_PARAM_NUMBER = 1,
|
|
75
|
+
RAC_TOOL_PARAM_BOOLEAN = 2,
|
|
76
|
+
RAC_TOOL_PARAM_OBJECT = 3,
|
|
77
|
+
RAC_TOOL_PARAM_ARRAY = 4
|
|
78
|
+
} rac_tool_param_type_t;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* @brief Tool parameter definition
|
|
82
|
+
*/
|
|
83
|
+
typedef struct rac_tool_parameter {
|
|
84
|
+
const char* name; /**< Parameter name */
|
|
85
|
+
rac_tool_param_type_t type; /**< Data type */
|
|
86
|
+
const char* description; /**< Human-readable description */
|
|
87
|
+
rac_bool_t required; /**< Whether required */
|
|
88
|
+
const char* enum_values; /**< JSON array of allowed values (can be NULL) */
|
|
89
|
+
} rac_tool_parameter_t;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* @brief Tool definition
|
|
93
|
+
*/
|
|
94
|
+
typedef struct rac_tool_definition {
|
|
95
|
+
const char* name; /**< Unique tool name (e.g., "get_weather") */
|
|
96
|
+
const char* description; /**< What the tool does */
|
|
97
|
+
const rac_tool_parameter_t* parameters; /**< Array of parameters */
|
|
98
|
+
size_t num_parameters; /**< Number of parameters */
|
|
99
|
+
const char* category; /**< Optional category (can be NULL) */
|
|
100
|
+
} rac_tool_definition_t;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* @brief Parsed tool call from LLM output
|
|
104
|
+
*/
|
|
105
|
+
typedef struct rac_tool_call {
|
|
106
|
+
rac_bool_t has_tool_call; /**< Whether a tool call was found */
|
|
107
|
+
char* tool_name; /**< Name of tool to execute (owned, must free) */
|
|
108
|
+
char* arguments_json; /**< Arguments as JSON string (owned, must free) */
|
|
109
|
+
char* clean_text; /**< Text without tool call tags (owned, must free) */
|
|
110
|
+
int64_t call_id; /**< Unique call ID for tracking */
|
|
111
|
+
rac_tool_call_format_t format; /**< Format that was detected/used for parsing */
|
|
112
|
+
} rac_tool_call_t;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* @brief Tool calling options
|
|
116
|
+
*/
|
|
117
|
+
typedef struct rac_tool_calling_options {
|
|
118
|
+
int32_t max_tool_calls; /**< Max tool calls per turn (default: 5) */
|
|
119
|
+
rac_bool_t auto_execute; /**< Auto-execute tools (default: true) */
|
|
120
|
+
float temperature; /**< Generation temperature */
|
|
121
|
+
int32_t max_tokens; /**< Max tokens to generate */
|
|
122
|
+
const char* system_prompt; /**< Optional system prompt */
|
|
123
|
+
rac_bool_t replace_system_prompt; /**< Replace vs append tool instructions */
|
|
124
|
+
rac_bool_t keep_tools_available; /**< Keep tools after first call */
|
|
125
|
+
rac_tool_call_format_t format; /**< Tool calling format (default: AUTO) */
|
|
126
|
+
} rac_tool_calling_options_t;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* @brief Default tool calling options
|
|
130
|
+
*/
|
|
131
|
+
#define RAC_TOOL_CALLING_OPTIONS_DEFAULT \
|
|
132
|
+
{ \
|
|
133
|
+
5, /* max_tool_calls */ \
|
|
134
|
+
1, /* auto_execute = true */ \
|
|
135
|
+
0.7f, /* temperature */ \
|
|
136
|
+
1024, /* max_tokens */ \
|
|
137
|
+
RAC_NULL, /* system_prompt */ \
|
|
138
|
+
0, /* replace_system_prompt = false */ \
|
|
139
|
+
0, /* keep_tools_available = false */ \
|
|
140
|
+
RAC_TOOL_FORMAT_DEFAULT /* format */ \
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// =============================================================================
|
|
144
|
+
// PARSING API - Single Source of Truth (NO FALLBACKS)
|
|
145
|
+
// =============================================================================
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* @brief Parse LLM output for tool calls (auto-detect format)
|
|
149
|
+
*
|
|
150
|
+
* *** THIS IS THE ONLY PARSING IMPLEMENTATION - ALL SDKS MUST USE THIS ***
|
|
151
|
+
*
|
|
152
|
+
* Auto-detects the tool calling format by checking for format-specific tags.
|
|
153
|
+
* Handles ALL edge cases for each format.
|
|
154
|
+
*
|
|
155
|
+
* @param llm_output Raw LLM output text
|
|
156
|
+
* @param out_result Output: Parsed result (caller must free with rac_tool_call_free)
|
|
157
|
+
* @return RAC_SUCCESS on success, error code otherwise
|
|
158
|
+
*/
|
|
159
|
+
RAC_API rac_result_t rac_tool_call_parse(const char* llm_output, rac_tool_call_t* out_result);
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* @brief Parse LLM output for tool calls with specified format
|
|
163
|
+
*
|
|
164
|
+
* Parses using a specific format.
|
|
165
|
+
*
|
|
166
|
+
* Supported formats:
|
|
167
|
+
* - RAC_TOOL_FORMAT_DEFAULT: <tool_call>JSON</tool_call>
|
|
168
|
+
* - RAC_TOOL_FORMAT_LFM2: <|tool_call_start|>[func(args)]<|tool_call_end|>
|
|
169
|
+
*
|
|
170
|
+
* @param llm_output Raw LLM output text
|
|
171
|
+
* @param format Tool calling format to use
|
|
172
|
+
* @param out_result Output: Parsed result (caller must free with rac_tool_call_free)
|
|
173
|
+
* @return RAC_SUCCESS on success, error code otherwise
|
|
174
|
+
*/
|
|
175
|
+
RAC_API rac_result_t rac_tool_call_parse_with_format(const char* llm_output,
|
|
176
|
+
rac_tool_call_format_t format,
|
|
177
|
+
rac_tool_call_t* out_result);
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* @brief Free tool call result
|
|
181
|
+
* @param result Result to free
|
|
182
|
+
*/
|
|
183
|
+
RAC_API void rac_tool_call_free(rac_tool_call_t* result);
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* @brief Get the human-readable name of a tool calling format
|
|
187
|
+
*
|
|
188
|
+
* @param format The format to get the name for
|
|
189
|
+
* @return Static string with the format name (do not free)
|
|
190
|
+
*/
|
|
191
|
+
RAC_API const char* rac_tool_call_format_name(rac_tool_call_format_t format);
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* @brief Detect which format is present in LLM output
|
|
195
|
+
*
|
|
196
|
+
* Checks for format-specific markers without fully parsing.
|
|
197
|
+
* Returns RAC_TOOL_FORMAT_DEFAULT if no recognizable format is found.
|
|
198
|
+
*
|
|
199
|
+
* @param llm_output Raw LLM output text
|
|
200
|
+
* @return Detected format, or RAC_TOOL_FORMAT_DEFAULT if none detected
|
|
201
|
+
*/
|
|
202
|
+
RAC_API rac_tool_call_format_t rac_tool_call_detect_format(const char* llm_output);
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* @brief Convert format name string to format enum
|
|
206
|
+
*
|
|
207
|
+
* This is the SINGLE SOURCE OF TRUTH for valid format names.
|
|
208
|
+
* SDKs should pass strings and let C++ handle the conversion.
|
|
209
|
+
*
|
|
210
|
+
* Valid names (case-insensitive): "default", "lfm2"
|
|
211
|
+
*
|
|
212
|
+
* @param name Format name string
|
|
213
|
+
* @return Corresponding format enum, or RAC_TOOL_FORMAT_DEFAULT if unknown
|
|
214
|
+
*/
|
|
215
|
+
RAC_API rac_tool_call_format_t rac_tool_call_format_from_name(const char* name);
|
|
216
|
+
|
|
217
|
+
// =============================================================================
|
|
218
|
+
// PROMPT FORMATTING API - All prompt building happens here
|
|
219
|
+
// =============================================================================
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* @brief Format tool definitions into system prompt (default format)
|
|
223
|
+
*
|
|
224
|
+
* Creates instruction text describing available tools and expected output format.
|
|
225
|
+
* Uses RAC_TOOL_FORMAT_DEFAULT (<tool_call>JSON</tool_call>).
|
|
226
|
+
*
|
|
227
|
+
* @param definitions Array of tool definitions
|
|
228
|
+
* @param num_definitions Number of definitions
|
|
229
|
+
* @param out_prompt Output: Allocated prompt string (caller must free with rac_free)
|
|
230
|
+
* @return RAC_SUCCESS on success, error code otherwise
|
|
231
|
+
*/
|
|
232
|
+
RAC_API rac_result_t rac_tool_call_format_prompt(const rac_tool_definition_t* definitions,
|
|
233
|
+
size_t num_definitions, char** out_prompt);
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* @brief Format tool definitions with specified format
|
|
237
|
+
*
|
|
238
|
+
* Creates instruction text using the specified tool calling format.
|
|
239
|
+
* Each format has different tag patterns and syntax instructions.
|
|
240
|
+
*
|
|
241
|
+
* @param definitions Array of tool definitions
|
|
242
|
+
* @param num_definitions Number of definitions
|
|
243
|
+
* @param format Tool calling format to use for instructions
|
|
244
|
+
* @param out_prompt Output: Allocated prompt string (caller must free with rac_free)
|
|
245
|
+
* @return RAC_SUCCESS on success, error code otherwise
|
|
246
|
+
*/
|
|
247
|
+
RAC_API rac_result_t rac_tool_call_format_prompt_with_format(const rac_tool_definition_t* definitions,
|
|
248
|
+
size_t num_definitions,
|
|
249
|
+
rac_tool_call_format_t format,
|
|
250
|
+
char** out_prompt);
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* @brief Format tools from JSON array string (default format)
|
|
254
|
+
*
|
|
255
|
+
* Convenience function when tools are provided as JSON.
|
|
256
|
+
*
|
|
257
|
+
* @param tools_json JSON array of tool definitions
|
|
258
|
+
* @param out_prompt Output: Allocated prompt string (caller must free with rac_free)
|
|
259
|
+
* @return RAC_SUCCESS on success, error code otherwise
|
|
260
|
+
*/
|
|
261
|
+
RAC_API rac_result_t rac_tool_call_format_prompt_json(const char* tools_json, char** out_prompt);
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* @brief Format tools from JSON array string with specified format
|
|
265
|
+
*
|
|
266
|
+
* @param tools_json JSON array of tool definitions
|
|
267
|
+
* @param format Tool calling format to use for instructions
|
|
268
|
+
* @param out_prompt Output: Allocated prompt string (caller must free with rac_free)
|
|
269
|
+
* @return RAC_SUCCESS on success, error code otherwise
|
|
270
|
+
*/
|
|
271
|
+
RAC_API rac_result_t rac_tool_call_format_prompt_json_with_format(const char* tools_json,
|
|
272
|
+
rac_tool_call_format_t format,
|
|
273
|
+
char** out_prompt);
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* @brief Format tools from JSON array string with format specified by name
|
|
277
|
+
*
|
|
278
|
+
* *** PREFERRED API FOR SDKS - Uses string format name ***
|
|
279
|
+
*
|
|
280
|
+
* Valid format names (case-insensitive): "default", "lfm2"
|
|
281
|
+
* Unknown names default to "default" format.
|
|
282
|
+
*
|
|
283
|
+
* @param tools_json JSON array of tool definitions
|
|
284
|
+
* @param format_name Format name string (e.g., "lfm2", "default")
|
|
285
|
+
* @param out_prompt Output: Allocated prompt string (caller must free with rac_free)
|
|
286
|
+
* @return RAC_SUCCESS on success, error code otherwise
|
|
287
|
+
*/
|
|
288
|
+
RAC_API rac_result_t rac_tool_call_format_prompt_json_with_format_name(const char* tools_json,
|
|
289
|
+
const char* format_name,
|
|
290
|
+
char** out_prompt);
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* @brief Build the initial prompt with tools and user query
|
|
294
|
+
*
|
|
295
|
+
* Combines system prompt, tool instructions, and user prompt.
|
|
296
|
+
*
|
|
297
|
+
* @param user_prompt The user's question/request
|
|
298
|
+
* @param tools_json JSON array of tool definitions
|
|
299
|
+
* @param options Tool calling options (can be NULL for defaults)
|
|
300
|
+
* @param out_prompt Output: Complete formatted prompt (caller must free with rac_free)
|
|
301
|
+
* @return RAC_SUCCESS on success, error code otherwise
|
|
302
|
+
*/
|
|
303
|
+
RAC_API rac_result_t rac_tool_call_build_initial_prompt(const char* user_prompt,
|
|
304
|
+
const char* tools_json,
|
|
305
|
+
const rac_tool_calling_options_t* options,
|
|
306
|
+
char** out_prompt);
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* @brief Build follow-up prompt after tool execution
|
|
310
|
+
*
|
|
311
|
+
* Creates the prompt to continue generation after a tool was executed.
|
|
312
|
+
* Handles both keepToolsAvailable=true and keepToolsAvailable=false cases.
|
|
313
|
+
*
|
|
314
|
+
* @param original_user_prompt The original user prompt
|
|
315
|
+
* @param tools_prompt The formatted tools prompt (can be NULL if not keeping tools)
|
|
316
|
+
* @param tool_name Name of the tool that was executed
|
|
317
|
+
* @param tool_result_json JSON string of the tool result
|
|
318
|
+
* @param keep_tools_available Whether to include tool definitions in follow-up
|
|
319
|
+
* @param out_prompt Output: Follow-up prompt (caller must free with rac_free)
|
|
320
|
+
* @return RAC_SUCCESS on success, error code otherwise
|
|
321
|
+
*/
|
|
322
|
+
RAC_API rac_result_t rac_tool_call_build_followup_prompt(const char* original_user_prompt,
|
|
323
|
+
const char* tools_prompt,
|
|
324
|
+
const char* tool_name,
|
|
325
|
+
const char* tool_result_json,
|
|
326
|
+
rac_bool_t keep_tools_available,
|
|
327
|
+
char** out_prompt);
|
|
328
|
+
|
|
329
|
+
// =============================================================================
|
|
330
|
+
// JSON UTILITY API - All JSON handling happens here
|
|
331
|
+
// =============================================================================
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* @brief Normalize JSON by adding quotes around unquoted keys
|
|
335
|
+
*
|
|
336
|
+
* Handles common LLM output patterns: {tool: "name"} → {"tool": "name"}
|
|
337
|
+
*
|
|
338
|
+
* @param json_str Input JSON string
|
|
339
|
+
* @param out_normalized Output: Normalized JSON (caller must free with rac_free)
|
|
340
|
+
* @return RAC_SUCCESS on success, error code otherwise
|
|
341
|
+
*/
|
|
342
|
+
RAC_API rac_result_t rac_tool_call_normalize_json(const char* json_str, char** out_normalized);
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* @brief Serialize tool definitions to JSON array
|
|
346
|
+
*
|
|
347
|
+
* @param definitions Array of tool definitions
|
|
348
|
+
* @param num_definitions Number of definitions
|
|
349
|
+
* @param out_json Output: JSON array string (caller must free with rac_free)
|
|
350
|
+
* @return RAC_SUCCESS on success, error code otherwise
|
|
351
|
+
*/
|
|
352
|
+
RAC_API rac_result_t rac_tool_call_definitions_to_json(const rac_tool_definition_t* definitions,
|
|
353
|
+
size_t num_definitions, char** out_json);
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* @brief Serialize a tool result to JSON
|
|
357
|
+
*
|
|
358
|
+
* @param tool_name Name of the tool
|
|
359
|
+
* @param success Whether execution succeeded
|
|
360
|
+
* @param result_json Result data as JSON (can be NULL)
|
|
361
|
+
* @param error_message Error message if failed (can be NULL)
|
|
362
|
+
* @param out_json Output: JSON string (caller must free with rac_free)
|
|
363
|
+
* @return RAC_SUCCESS on success, error code otherwise
|
|
364
|
+
*/
|
|
365
|
+
RAC_API rac_result_t rac_tool_call_result_to_json(const char* tool_name, rac_bool_t success,
|
|
366
|
+
const char* result_json,
|
|
367
|
+
const char* error_message, char** out_json);
|
|
368
|
+
|
|
369
|
+
#ifdef __cplusplus
|
|
370
|
+
}
|
|
371
|
+
#endif
|
|
372
|
+
|
|
373
|
+
#endif /* RAC_TOOL_CALLING_H */
|
|
@@ -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,
|
|
170
|
-
RAC_CAPABILITY_EMBEDDINGS = 2,
|
|
171
|
-
RAC_CAPABILITY_STT = 3,
|
|
172
|
-
RAC_CAPABILITY_TTS = 4,
|
|
173
|
-
RAC_CAPABILITY_VAD = 5,
|
|
174
|
-
RAC_CAPABILITY_DIARIZATION = 6,
|
|
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
|
/**
|
|
@@ -232,7 +232,7 @@ RAC_API rac_result_t rac_energy_vad_process_audio(rac_energy_vad_handle_t handle
|
|
|
232
232
|
* @param sample_count Number of samples
|
|
233
233
|
* @return RMS energy value, or 0.0 if empty
|
|
234
234
|
*/
|
|
235
|
-
RAC_API float rac_energy_vad_calculate_rms(const float* audio_data,
|
|
235
|
+
RAC_API float rac_energy_vad_calculate_rms(const float* __restrict audio_data,size_t sample_count);
|
|
236
236
|
|
|
237
237
|
// =============================================================================
|
|
238
238
|
// PAUSE/RESUME API
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file rac_vlm.h
|
|
3
|
+
* @brief RunAnywhere Commons - VLM Public API
|
|
4
|
+
*
|
|
5
|
+
* Convenience header that includes all VLM-related headers.
|
|
6
|
+
* Use this for complete VLM API access.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
#ifndef RAC_VLM_H
|
|
10
|
+
#define RAC_VLM_H
|
|
11
|
+
|
|
12
|
+
#include <RACommons/rac_vlm_component.h>
|
|
13
|
+
#include <RACommons/rac_vlm_service.h>
|
|
14
|
+
#include <RACommons/rac_vlm_types.h>
|
|
15
|
+
|
|
16
|
+
#endif /* RAC_VLM_H */
|