cactus-react-native 1.5.0 → 1.7.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 (216) hide show
  1. package/Cactus.podspec +1 -1
  2. package/README.md +347 -241
  3. package/android/CMakeLists.txt +24 -5
  4. package/android/src/main/jniLibs/arm64-v8a/libcactus.a +0 -0
  5. package/android/src/main/jniLibs/arm64-v8a/libcurl.a +0 -0
  6. package/android/src/main/jniLibs/arm64-v8a/libmbedcrypto.a +0 -0
  7. package/android/src/main/jniLibs/arm64-v8a/libmbedtls.a +0 -0
  8. package/android/src/main/jniLibs/arm64-v8a/libmbedx509.a +0 -0
  9. package/cpp/HybridCactus.cpp +149 -117
  10. package/cpp/HybridCactus.hpp +14 -10
  11. package/cpp/cactus_ffi.h +54 -43
  12. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/cactus.h +0 -1
  13. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/cactus_ffi.h +54 -43
  14. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/cactus_utils.h +318 -123
  15. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/engine.h +118 -15
  16. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/graph.h +77 -32
  17. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/kernel.h +68 -6
  18. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/kernel_utils.h +21 -155
  19. package/ios/cactus.xcframework/ios-arm64/cactus.framework/cactus +0 -0
  20. package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/cactus.h +0 -1
  21. package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/cactus_ffi.h +54 -43
  22. package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/cactus_utils.h +318 -123
  23. package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/engine.h +118 -15
  24. package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/graph.h +77 -32
  25. package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/kernel.h +68 -6
  26. package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/kernel_utils.h +21 -155
  27. package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/cactus +0 -0
  28. package/lib/module/classes/CactusLM.js +16 -49
  29. package/lib/module/classes/CactusLM.js.map +1 -1
  30. package/lib/module/classes/CactusSTT.js +30 -79
  31. package/lib/module/classes/CactusSTT.js.map +1 -1
  32. package/lib/module/classes/CactusVAD.js +95 -0
  33. package/lib/module/classes/CactusVAD.js.map +1 -0
  34. package/lib/module/hooks/useCactusLM.js +10 -11
  35. package/lib/module/hooks/useCactusLM.js.map +1 -1
  36. package/lib/module/hooks/useCactusSTT.js +23 -62
  37. package/lib/module/hooks/useCactusSTT.js.map +1 -1
  38. package/lib/module/hooks/useCactusVAD.js +171 -0
  39. package/lib/module/hooks/useCactusVAD.js.map +1 -0
  40. package/lib/module/index.js +2 -3
  41. package/lib/module/index.js.map +1 -1
  42. package/lib/module/modelRegistry.js +52 -0
  43. package/lib/module/modelRegistry.js.map +1 -0
  44. package/lib/module/native/Cactus.js +85 -23
  45. package/lib/module/native/Cactus.js.map +1 -1
  46. package/lib/module/native/CactusIndex.js.map +1 -1
  47. package/lib/module/native/index.js +0 -3
  48. package/lib/module/native/index.js.map +1 -1
  49. package/lib/module/types/CactusVAD.js +4 -0
  50. package/lib/module/{specs/CactusUtil.nitro.js.map → types/CactusVAD.js.map} +1 -1
  51. package/lib/typescript/src/classes/CactusLM.d.ts +5 -7
  52. package/lib/typescript/src/classes/CactusLM.d.ts.map +1 -1
  53. package/lib/typescript/src/classes/CactusSTT.d.ts +8 -12
  54. package/lib/typescript/src/classes/CactusSTT.d.ts.map +1 -1
  55. package/lib/typescript/src/classes/CactusVAD.d.ts +20 -0
  56. package/lib/typescript/src/classes/CactusVAD.d.ts.map +1 -0
  57. package/lib/typescript/src/hooks/useCactusLM.d.ts +2 -2
  58. package/lib/typescript/src/hooks/useCactusLM.d.ts.map +1 -1
  59. package/lib/typescript/src/hooks/useCactusSTT.d.ts +6 -8
  60. package/lib/typescript/src/hooks/useCactusSTT.d.ts.map +1 -1
  61. package/lib/typescript/src/hooks/useCactusVAD.d.ts +15 -0
  62. package/lib/typescript/src/hooks/useCactusVAD.d.ts.map +1 -0
  63. package/lib/typescript/src/index.d.ts +7 -5
  64. package/lib/typescript/src/index.d.ts.map +1 -1
  65. package/lib/typescript/src/modelRegistry.d.ts +5 -0
  66. package/lib/typescript/src/modelRegistry.d.ts.map +1 -0
  67. package/lib/typescript/src/native/Cactus.d.ts +12 -11
  68. package/lib/typescript/src/native/Cactus.d.ts.map +1 -1
  69. package/lib/typescript/src/native/CactusIndex.d.ts +2 -2
  70. package/lib/typescript/src/native/CactusIndex.d.ts.map +1 -1
  71. package/lib/typescript/src/native/index.d.ts +0 -3
  72. package/lib/typescript/src/native/index.d.ts.map +1 -1
  73. package/lib/typescript/src/specs/Cactus.nitro.d.ts +6 -6
  74. package/lib/typescript/src/specs/Cactus.nitro.d.ts.map +1 -1
  75. package/lib/typescript/src/types/CactusIndex.d.ts +2 -2
  76. package/lib/typescript/src/types/CactusIndex.d.ts.map +1 -1
  77. package/lib/typescript/src/types/CactusLM.d.ts +19 -11
  78. package/lib/typescript/src/types/CactusLM.d.ts.map +1 -1
  79. package/lib/typescript/src/types/CactusSTT.d.ts +33 -12
  80. package/lib/typescript/src/types/CactusSTT.d.ts.map +1 -1
  81. package/lib/typescript/src/types/CactusVAD.d.ts +34 -0
  82. package/lib/typescript/src/types/CactusVAD.d.ts.map +1 -0
  83. package/lib/typescript/src/types/common.d.ts +1 -6
  84. package/lib/typescript/src/types/common.d.ts.map +1 -1
  85. package/nitro.json +0 -11
  86. package/nitrogen/generated/android/cactus+autolinking.cmake +0 -5
  87. package/nitrogen/generated/android/cactusOnLoad.cpp +0 -30
  88. package/nitrogen/generated/ios/Cactus-Swift-Cxx-Bridge.cpp +0 -50
  89. package/nitrogen/generated/ios/Cactus-Swift-Cxx-Bridge.hpp +9 -147
  90. package/nitrogen/generated/ios/Cactus-Swift-Cxx-Umbrella.hpp +0 -13
  91. package/nitrogen/generated/ios/CactusAutolinking.mm +0 -26
  92. package/nitrogen/generated/ios/CactusAutolinking.swift +0 -30
  93. package/nitrogen/generated/shared/c++/HybridCactusSpec.cpp +4 -4
  94. package/nitrogen/generated/shared/c++/HybridCactusSpec.hpp +6 -6
  95. package/package.json +3 -3
  96. package/src/classes/CactusLM.ts +18 -65
  97. package/src/classes/CactusSTT.ts +39 -97
  98. package/src/classes/CactusVAD.ts +129 -0
  99. package/src/hooks/useCactusLM.ts +14 -17
  100. package/src/hooks/useCactusSTT.ts +47 -98
  101. package/src/hooks/useCactusVAD.ts +215 -0
  102. package/src/index.tsx +18 -12
  103. package/src/modelRegistry.ts +65 -0
  104. package/src/native/Cactus.ts +102 -41
  105. package/src/native/CactusIndex.ts +2 -2
  106. package/src/native/index.ts +0 -3
  107. package/src/specs/Cactus.nitro.ts +11 -7
  108. package/src/types/CactusIndex.ts +2 -2
  109. package/src/types/CactusLM.ts +19 -11
  110. package/src/types/CactusSTT.ts +33 -13
  111. package/src/types/CactusVAD.ts +39 -0
  112. package/src/types/common.ts +1 -6
  113. package/android/src/main/java/com/margelo/nitro/cactus/HybridCactusCrypto.kt +0 -46
  114. package/android/src/main/java/com/margelo/nitro/cactus/HybridCactusDeviceInfo.kt +0 -27
  115. package/android/src/main/jniLibs/arm64-v8a/libcactus_util.a +0 -0
  116. package/cpp/HybridCactusUtil.cpp +0 -47
  117. package/cpp/HybridCactusUtil.hpp +0 -27
  118. package/cpp/cactus_util.h +0 -25
  119. package/ios/HybridCactusCrypto.swift +0 -37
  120. package/ios/HybridCactusDeviceInfo.swift +0 -32
  121. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/cactus_telemetry.h +0 -656
  122. package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/cactus_telemetry.h +0 -656
  123. package/ios/cactus_util.xcframework/Info.plist +0 -39
  124. package/ios/cactus_util.xcframework/ios-arm64/cactus_util.framework/Headers/cactus_util.h +0 -25
  125. package/ios/cactus_util.xcframework/ios-arm64/cactus_util.framework/Headers/database.h +0 -27
  126. package/ios/cactus_util.xcframework/ios-arm64/cactus_util.framework/Headers/ios_utils.h +0 -10
  127. package/ios/cactus_util.xcframework/ios-arm64/cactus_util.framework/Headers/logging.h +0 -25
  128. package/ios/cactus_util.xcframework/ios-arm64/cactus_util.framework/Info.plist +0 -0
  129. package/ios/cactus_util.xcframework/ios-arm64/cactus_util.framework/cactus_util +0 -0
  130. package/ios/cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework/Headers/cactus_util.h +0 -25
  131. package/ios/cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework/Headers/database.h +0 -27
  132. package/ios/cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework/Headers/ios_utils.h +0 -10
  133. package/ios/cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework/Headers/logging.h +0 -25
  134. package/ios/cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework/Info.plist +0 -0
  135. package/ios/cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework/_CodeSignature/CodeResources +0 -135
  136. package/ios/cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework/cactus_util +0 -0
  137. package/lib/module/api/Database.js +0 -45
  138. package/lib/module/api/Database.js.map +0 -1
  139. package/lib/module/api/RemoteLM.js +0 -201
  140. package/lib/module/api/RemoteLM.js.map +0 -1
  141. package/lib/module/config/CactusConfig.js +0 -12
  142. package/lib/module/config/CactusConfig.js.map +0 -1
  143. package/lib/module/models.js +0 -336
  144. package/lib/module/models.js.map +0 -1
  145. package/lib/module/native/CactusCrypto.js +0 -10
  146. package/lib/module/native/CactusCrypto.js.map +0 -1
  147. package/lib/module/native/CactusDeviceInfo.js +0 -13
  148. package/lib/module/native/CactusDeviceInfo.js.map +0 -1
  149. package/lib/module/native/CactusUtil.js +0 -36
  150. package/lib/module/native/CactusUtil.js.map +0 -1
  151. package/lib/module/specs/CactusCrypto.nitro.js +0 -4
  152. package/lib/module/specs/CactusCrypto.nitro.js.map +0 -1
  153. package/lib/module/specs/CactusDeviceInfo.nitro.js +0 -4
  154. package/lib/module/specs/CactusDeviceInfo.nitro.js.map +0 -1
  155. package/lib/module/specs/CactusUtil.nitro.js +0 -4
  156. package/lib/module/telemetry/Telemetry.js +0 -154
  157. package/lib/module/telemetry/Telemetry.js.map +0 -1
  158. package/lib/typescript/src/api/Database.d.ts +0 -12
  159. package/lib/typescript/src/api/Database.d.ts.map +0 -1
  160. package/lib/typescript/src/api/RemoteLM.d.ts +0 -14
  161. package/lib/typescript/src/api/RemoteLM.d.ts.map +0 -1
  162. package/lib/typescript/src/config/CactusConfig.d.ts +0 -7
  163. package/lib/typescript/src/config/CactusConfig.d.ts.map +0 -1
  164. package/lib/typescript/src/models.d.ts +0 -6
  165. package/lib/typescript/src/models.d.ts.map +0 -1
  166. package/lib/typescript/src/native/CactusCrypto.d.ts +0 -5
  167. package/lib/typescript/src/native/CactusCrypto.d.ts.map +0 -1
  168. package/lib/typescript/src/native/CactusDeviceInfo.d.ts +0 -7
  169. package/lib/typescript/src/native/CactusDeviceInfo.d.ts.map +0 -1
  170. package/lib/typescript/src/native/CactusUtil.d.ts +0 -6
  171. package/lib/typescript/src/native/CactusUtil.d.ts.map +0 -1
  172. package/lib/typescript/src/specs/CactusCrypto.nitro.d.ts +0 -8
  173. package/lib/typescript/src/specs/CactusCrypto.nitro.d.ts.map +0 -1
  174. package/lib/typescript/src/specs/CactusDeviceInfo.nitro.d.ts +0 -16
  175. package/lib/typescript/src/specs/CactusDeviceInfo.nitro.d.ts.map +0 -1
  176. package/lib/typescript/src/specs/CactusUtil.nitro.d.ts +0 -10
  177. package/lib/typescript/src/specs/CactusUtil.nitro.d.ts.map +0 -1
  178. package/lib/typescript/src/telemetry/Telemetry.d.ts +0 -34
  179. package/lib/typescript/src/telemetry/Telemetry.d.ts.map +0 -1
  180. package/nitrogen/generated/android/c++/JDeviceInfo.hpp +0 -74
  181. package/nitrogen/generated/android/c++/JHybridCactusCryptoSpec.cpp +0 -65
  182. package/nitrogen/generated/android/c++/JHybridCactusCryptoSpec.hpp +0 -65
  183. package/nitrogen/generated/android/c++/JHybridCactusDeviceInfoSpec.cpp +0 -85
  184. package/nitrogen/generated/android/c++/JHybridCactusDeviceInfoSpec.hpp +0 -66
  185. package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/DeviceInfo.kt +0 -50
  186. package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/HybridCactusCryptoSpec.kt +0 -58
  187. package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/HybridCactusDeviceInfoSpec.kt +0 -62
  188. package/nitrogen/generated/ios/c++/HybridCactusCryptoSpecSwift.cpp +0 -11
  189. package/nitrogen/generated/ios/c++/HybridCactusCryptoSpecSwift.hpp +0 -77
  190. package/nitrogen/generated/ios/c++/HybridCactusDeviceInfoSpecSwift.cpp +0 -11
  191. package/nitrogen/generated/ios/c++/HybridCactusDeviceInfoSpecSwift.hpp +0 -88
  192. package/nitrogen/generated/ios/swift/DeviceInfo.swift +0 -98
  193. package/nitrogen/generated/ios/swift/Func_void_DeviceInfo.swift +0 -47
  194. package/nitrogen/generated/ios/swift/Func_void_std__optional_std__string_.swift +0 -54
  195. package/nitrogen/generated/ios/swift/HybridCactusCryptoSpec.swift +0 -57
  196. package/nitrogen/generated/ios/swift/HybridCactusCryptoSpec_cxx.swift +0 -139
  197. package/nitrogen/generated/ios/swift/HybridCactusDeviceInfoSpec.swift +0 -58
  198. package/nitrogen/generated/ios/swift/HybridCactusDeviceInfoSpec_cxx.swift +0 -164
  199. package/nitrogen/generated/shared/c++/DeviceInfo.hpp +0 -92
  200. package/nitrogen/generated/shared/c++/HybridCactusCryptoSpec.cpp +0 -21
  201. package/nitrogen/generated/shared/c++/HybridCactusCryptoSpec.hpp +0 -63
  202. package/nitrogen/generated/shared/c++/HybridCactusDeviceInfoSpec.cpp +0 -22
  203. package/nitrogen/generated/shared/c++/HybridCactusDeviceInfoSpec.hpp +0 -67
  204. package/nitrogen/generated/shared/c++/HybridCactusUtilSpec.cpp +0 -23
  205. package/nitrogen/generated/shared/c++/HybridCactusUtilSpec.hpp +0 -66
  206. package/src/api/Database.ts +0 -55
  207. package/src/api/RemoteLM.ts +0 -273
  208. package/src/config/CactusConfig.ts +0 -11
  209. package/src/models.ts +0 -344
  210. package/src/native/CactusCrypto.ts +0 -11
  211. package/src/native/CactusDeviceInfo.ts +0 -18
  212. package/src/native/CactusUtil.ts +0 -43
  213. package/src/specs/CactusCrypto.nitro.ts +0 -6
  214. package/src/specs/CactusDeviceInfo.nitro.ts +0 -15
  215. package/src/specs/CactusUtil.nitro.ts +0 -8
  216. package/src/telemetry/Telemetry.ts +0 -236
package/README.md CHANGED
@@ -15,7 +15,7 @@ npm install cactus-react-native react-native-nitro-modules
15
15
  Get started with Cactus in just a few lines of code:
16
16
 
17
17
  ```typescript
18
- import { CactusLM, type Message } from 'cactus-react-native';
18
+ import { CactusLM, type CactusLMMessage } from 'cactus-react-native';
19
19
 
20
20
  // Create a new instance
21
21
  const cactusLM = new CactusLM();
@@ -26,7 +26,7 @@ await cactusLM.download({
26
26
  });
27
27
 
28
28
  // Generate a completion
29
- const messages: Message[] = [
29
+ const messages: CactusLMMessage[] = [
30
30
  { role: 'user', content: 'What is the capital of France?' }
31
31
  ];
32
32
 
@@ -85,11 +85,11 @@ Choose model quantization and NPU acceleration with Pro models.
85
85
  ```typescript
86
86
  import { CactusLM } from 'cactus-react-native';
87
87
 
88
- // Use int4 for faster performance and smaller file size
88
+ // Use int8 for better accuracy (default)
89
89
  const cactusLM = new CactusLM({
90
90
  model: 'lfm2-vl-450m',
91
91
  options: {
92
- quantization: 'int4', // 'int4' or 'int8'
92
+ quantization: 'int8', // 'int4' or 'int8'
93
93
  pro: false
94
94
  }
95
95
  });
@@ -98,7 +98,7 @@ const cactusLM = new CactusLM({
98
98
  const cactusPro = new CactusLM({
99
99
  model: 'lfm2-vl-450m',
100
100
  options: {
101
- quantization: 'int4',
101
+ quantization: 'int8',
102
102
  pro: true
103
103
  }
104
104
  });
@@ -111,11 +111,11 @@ Generate text responses from the model by providing a conversation history.
111
111
  #### Class
112
112
 
113
113
  ```typescript
114
- import { CactusLM, type Message } from 'cactus-react-native';
114
+ import { CactusLM, type CactusLMMessage } from 'cactus-react-native';
115
115
 
116
116
  const cactusLM = new CactusLM();
117
117
 
118
- const messages: Message[] = [{ role: 'user', content: 'Hello, World!' }];
118
+ const messages: CactusLMMessage[] = [{ role: 'user', content: 'Hello, World!' }];
119
119
  const onToken = (token: string) => { console.log('Token:', token) };
120
120
 
121
121
  const result = await cactusLM.complete({ messages, onToken });
@@ -125,13 +125,13 @@ console.log('Completion result:', result);
125
125
  #### Hook
126
126
 
127
127
  ```tsx
128
- import { useCactusLM, type Message } from 'cactus-react-native';
128
+ import { useCactusLM, type CactusLMMessage } from 'cactus-react-native';
129
129
 
130
130
  const App = () => {
131
131
  const cactusLM = useCactusLM();
132
132
 
133
133
  const handleComplete = async () => {
134
- const messages: Message[] = [{ role: 'user', content: 'Hello, World!' }];
134
+ const messages: CactusLMMessage[] = [{ role: 'user', content: 'Hello, World!' }];
135
135
 
136
136
  const result = await cactusLM.complete({ messages });
137
137
  console.log('Completion result:', result);
@@ -153,12 +153,12 @@ Vision allows you to pass images along with text prompts, enabling the model to
153
153
  #### Class
154
154
 
155
155
  ```typescript
156
- import { CactusLM, type Message } from 'cactus-react-native';
156
+ import { CactusLM, type CactusLMMessage } from 'cactus-react-native';
157
157
 
158
158
  // Vision-capable model
159
159
  const cactusLM = new CactusLM({ model: 'lfm2-vl-450m' });
160
160
 
161
- const messages: Message[] = [
161
+ const messages: CactusLMMessage[] = [
162
162
  {
163
163
  role: 'user',
164
164
  content: "What's in the image?",
@@ -173,14 +173,14 @@ console.log('Response:', result.response);
173
173
  #### Hook
174
174
 
175
175
  ```tsx
176
- import { useCactusLM, type Message } from 'cactus-react-native';
176
+ import { useCactusLM, type CactusLMMessage } from 'cactus-react-native';
177
177
 
178
178
  const App = () => {
179
179
  // Vision-capable model
180
180
  const cactusLM = useCactusLM({ model: 'lfm2-vl-450m' });
181
181
 
182
182
  const handleAnalyze = async () => {
183
- const messages: Message[] = [
183
+ const messages: CactusLMMessage[] = [
184
184
  {
185
185
  role: 'user',
186
186
  content: "What's in the image?",
@@ -207,9 +207,9 @@ Enable the model to generate function calls by defining available tools and thei
207
207
  #### Class
208
208
 
209
209
  ```typescript
210
- import { CactusLM, type Message, type Tool } from 'cactus-react-native';
210
+ import { CactusLM, type CactusLMMessage, type CactusLMTool } from 'cactus-react-native';
211
211
 
212
- const tools: Tool[] = [
212
+ const tools: CactusLMTool[] = [
213
213
  {
214
214
  name: 'get_weather',
215
215
  description: 'Get current weather for a location',
@@ -228,7 +228,7 @@ const tools: Tool[] = [
228
228
 
229
229
  const cactusLM = new CactusLM();
230
230
 
231
- const messages: Message[] = [
231
+ const messages: CactusLMMessage[] = [
232
232
  { role: 'user', content: "What's the weather in San Francisco?" },
233
233
  ];
234
234
 
@@ -240,9 +240,9 @@ console.log('Function calls:', result.functionCalls);
240
240
  #### Hook
241
241
 
242
242
  ```tsx
243
- import { useCactusLM, type Message, type Tool } from 'cactus-react-native';
243
+ import { useCactusLM, type CactusLMMessage, type CactusLMTool } from 'cactus-react-native';
244
244
 
245
- const tools: Tool[] = [
245
+ const tools: CactusLMTool[] = [
246
246
  {
247
247
  name: 'get_weather',
248
248
  description: 'Get current weather for a location',
@@ -263,7 +263,7 @@ const App = () => {
263
263
  const cactusLM = useCactusLM();
264
264
 
265
265
  const handleComplete = async () => {
266
- const messages: Message[] = [
266
+ const messages: CactusLMMessage[] = [
267
267
  { role: 'user', content: "What's the weather in San Francisco?" },
268
268
  ];
269
269
 
@@ -283,13 +283,13 @@ RAG allows you to provide a corpus of documents that the model can reference dur
283
283
  #### Class
284
284
 
285
285
  ```typescript
286
- import { CactusLM, type Message } from 'cactus-react-native';
286
+ import { CactusLM, type CactusLMMessage } from 'cactus-react-native';
287
287
 
288
288
  const cactusLM = new CactusLM({
289
289
  corpusDir: 'path/to/your/corpus', // Directory containing .txt files
290
290
  });
291
291
 
292
- const messages: Message[] = [
292
+ const messages: CactusLMMessage[] = [
293
293
  { role: 'user', content: 'What information is in the documents?' },
294
294
  ];
295
295
 
@@ -300,7 +300,7 @@ console.log(result.response);
300
300
  #### Hook
301
301
 
302
302
  ```tsx
303
- import { useCactusLM, type Message } from 'cactus-react-native';
303
+ import { useCactusLM, type CactusLMMessage } from 'cactus-react-native';
304
304
 
305
305
  const App = () => {
306
306
  const cactusLM = useCactusLM({
@@ -308,7 +308,7 @@ const App = () => {
308
308
  });
309
309
 
310
310
  const handleAsk = async () => {
311
- const messages: Message[] = [
311
+ const messages: CactusLMMessage[] = [
312
312
  { role: 'user', content: 'What information is in the documents?' },
313
313
  ];
314
314
 
@@ -468,60 +468,9 @@ const App = () => {
468
468
  };
469
469
  ```
470
470
 
471
- ### Hybrid Mode (Cloud Fallback)
472
-
473
- The CactusLM supports a hybrid completion mode that falls back to a cloud-based LLM provider `OpenRouter` if local inference fails.
474
-
475
- #### Class
476
-
477
- ```typescript
478
- import { CactusLM, type Message } from 'cactus-react-native';
479
-
480
- const cactusLM = new CactusLM();
481
-
482
- const messages: Message[] = [
483
- { role: 'user', content: 'Hello, World!' }
484
- ];
485
-
486
- // Falls back to remote if local fails
487
- const result = await cactusLM.complete({
488
- messages,
489
- mode: 'hybrid'
490
- });
491
- ```
492
-
493
- #### Hook
494
-
495
- ```tsx
496
- import { useCactusLM, type Message } from 'cactus-react-native';
497
-
498
- const App = () => {
499
- const cactusLM = useCactusLM();
500
-
501
- const handleComplete = async () => {
502
- const messages: Message[] = [
503
- { role: 'user', content: 'Hello, World!' }
504
- ];
505
-
506
- // Falls back to remote if local fails
507
- await cactusLM.complete({
508
- messages,
509
- mode: 'hybrid'
510
- });
511
- };
512
-
513
- return (
514
- <>
515
- <Button title="Complete" onPress={handleComplete} />
516
- <Text>{cactusLM.completion}</Text>
517
- </>
518
- );
519
- };
520
- ```
521
-
522
471
  ## Speech-to-Text (STT)
523
472
 
524
- The `CactusSTT` class provides audio transcription and audio embedding capabilities using Whisper models.
473
+ The `CactusSTT` class provides audio transcription and audio embedding capabilities using speech-to-text models such as Whisper and Moonshine.
525
474
 
526
475
  ### Transcription
527
476
 
@@ -534,8 +483,6 @@ import { CactusSTT } from 'cactus-react-native';
534
483
 
535
484
  const cactusSTT = new CactusSTT({ model: 'whisper-small' });
536
485
 
537
- await cactusSTT.init();
538
-
539
486
  // Transcribe from file path
540
487
  const result = await cactusSTT.transcribe({
541
488
  audio: 'path/to/audio.wav',
@@ -587,7 +534,7 @@ const App = () => {
587
534
 
588
535
  ### Streaming Transcription
589
536
 
590
- Transcribe audio in real-time with incremental results.
537
+ Transcribe audio in real-time with incremental results. Each call to `streamTranscribeProcess` feeds an audio chunk and returns the currently confirmed and pending text.
591
538
 
592
539
  #### Class
593
540
 
@@ -596,20 +543,19 @@ import { CactusSTT } from 'cactus-react-native';
596
543
 
597
544
  const cactusSTT = new CactusSTT({ model: 'whisper-small' });
598
545
 
599
- await cactusSTT.streamTranscribeInit();
600
-
601
- const audioChunk: number[] = [/* PCM samples */];
602
- await cactusSTT.streamTranscribeInsert({ audio: audioChunk });
603
-
604
- const result = await cactusSTT.streamTranscribeProcess({
605
- options: { confirmationThreshold: 0.95 }
546
+ await cactusSTT.streamTranscribeStart({
547
+ confirmationThreshold: 0.99, // confidence required to confirm text
548
+ minChunkSize: 32000, // minimum samples before processing
606
549
  });
607
550
 
551
+ const audioChunk: number[] = [/* PCM samples as bytes */];
552
+ const result = await cactusSTT.streamTranscribeProcess({ audio: audioChunk });
553
+
608
554
  console.log('Confirmed:', result.confirmed);
609
555
  console.log('Pending:', result.pending);
610
556
 
611
- const final = await cactusSTT.streamTranscribeFinalize();
612
- await cactusSTT.streamTranscribeDestroy();
557
+ const final = await cactusSTT.streamTranscribeStop();
558
+ console.log('Final confirmed:', final.confirmed);
613
559
  ```
614
560
 
615
561
  #### Hook
@@ -620,18 +566,25 @@ import { useCactusSTT } from 'cactus-react-native';
620
566
  const App = () => {
621
567
  const cactusSTT = useCactusSTT({ model: 'whisper-small' });
622
568
 
623
- const handleStream = async () => {
624
- await cactusSTT.streamTranscribeInit();
569
+ const handleStart = async () => {
570
+ await cactusSTT.streamTranscribeStart({ confirmationThreshold: 0.99 });
571
+ };
625
572
 
626
- const audioChunk: number[] = [/* PCM samples */];
627
- await cactusSTT.streamTranscribeInsert({ audio: audioChunk });
573
+ const handleChunk = async (audioChunk: number[]) => {
574
+ const result = await cactusSTT.streamTranscribeProcess({ audio: audioChunk });
575
+ console.log('Confirmed:', result.confirmed);
576
+ console.log('Pending:', result.pending);
577
+ };
628
578
 
629
- await cactusSTT.streamTranscribeProcess();
579
+ const handleStop = async () => {
580
+ const final = await cactusSTT.streamTranscribeStop();
581
+ console.log('Final:', final.confirmed);
630
582
  };
631
583
 
632
584
  return (
633
585
  <>
634
- <Button onPress={handleStream} title="Stream" />
586
+ <Button onPress={handleStart} title="Start" />
587
+ <Button onPress={handleStop} title="Stop" />
635
588
  <Text>{cactusSTT.streamTranscribeConfirmed}</Text>
636
589
  <Text>{cactusSTT.streamTranscribePending}</Text>
637
590
  </>
@@ -650,8 +603,6 @@ import { CactusSTT } from 'cactus-react-native';
650
603
 
651
604
  const cactusSTT = new CactusSTT();
652
605
 
653
- await cactusSTT.init();
654
-
655
606
  const result = await cactusSTT.audioEmbed({
656
607
  audioPath: 'path/to/audio.wav'
657
608
  });
@@ -680,6 +631,50 @@ const App = () => {
680
631
  };
681
632
  ```
682
633
 
634
+ ## Voice Activity Detection (VAD)
635
+
636
+ The `CactusVAD` class detects speech segments in audio, returning timestamped intervals where speech is present.
637
+
638
+ ### Class
639
+
640
+ ```typescript
641
+ import { CactusVAD } from 'cactus-react-native';
642
+
643
+ const cactusVAD = new CactusVAD({ model: 'silero-vad' });
644
+
645
+ const result = await cactusVAD.vad({
646
+ audio: 'path/to/audio.wav',
647
+ options: {
648
+ threshold: 0.5,
649
+ minSpeechDurationMs: 250,
650
+ minSilenceDurationMs: 100,
651
+ }
652
+ });
653
+
654
+ console.log('Speech segments:', result.segments);
655
+ // [{ start: 0, end: 16000 }, { start: 32000, end: 48000 }, ...]
656
+ console.log('Total time (ms):', result.totalTime);
657
+ ```
658
+
659
+ ### Hook
660
+
661
+ ```tsx
662
+ import { useCactusVAD } from 'cactus-react-native';
663
+
664
+ const App = () => {
665
+ const cactusVAD = useCactusVAD({ model: 'silero-vad' });
666
+
667
+ const handleVAD = async () => {
668
+ const result = await cactusVAD.vad({
669
+ audio: 'path/to/audio.wav',
670
+ });
671
+ console.log('Speech segments:', result.segments);
672
+ };
673
+
674
+ return <Button title="Detect Speech" onPress={handleVAD} />;
675
+ };
676
+ ```
677
+
683
678
  ## Vector Index
684
679
 
685
680
  The `CactusIndex` class provides a vector database for storing and querying embeddings with metadata. Enabling similarity search and retrieval.
@@ -934,11 +929,11 @@ const App = () => {
934
929
  **`new CactusLM(params?: CactusLMParams)`**
935
930
 
936
931
  **Parameters:**
937
- - `model` - Model slug or absolute path to Cactus model (default: `'qwen3-0.6b'`).
938
- - `contextSize` - Context window size (default: `2048`).
932
+ - `model` - Model slug or absolute path to a model file (default: `'qwen3-0.6b'`).
939
933
  - `corpusDir` - Directory containing text files for RAG (default: `undefined`).
934
+ - `cacheIndex` - Whether to cache the RAG corpus index on disk (default: `false`).
940
935
  - `options` - Model options for quantization and NPU acceleration:
941
- - `quantization` - Quantization type: `'int4'` | `'int8'` (default: `'int4'`).
936
+ - `quantization` - Quantization type: `'int4'` | `'int8'` (default: `'int8'`).
942
937
  - `pro` - Enable NPU-accelerated models (default: `false`).
943
938
 
944
939
  #### Methods
@@ -959,17 +954,21 @@ Initializes the model and prepares it for inference. Safe to call multiple times
959
954
  Performs text completion with optional streaming and tool support. Automatically calls `init()` if not already initialized. Throws an error if a generation (completion or embedding) is already in progress.
960
955
 
961
956
  **Parameters:**
962
- - `messages` - Array of `Message` objects.
957
+ - `messages` - Array of `CactusLMMessage` objects.
963
958
  - `options` - Generation options:
964
- - `temperature` - Sampling temperature (default: model-optimized).
965
- - `topP` - Nucleus sampling threshold (default: model-optimized).
966
- - `topK` - Top-K sampling limit (default: model-optimized).
959
+ - `temperature` - Sampling temperature.
960
+ - `topP` - Nucleus sampling threshold.
961
+ - `topK` - Top-K sampling limit.
967
962
  - `maxTokens` - Maximum number of tokens to generate (default: `512`).
968
- - `stopSequences` - Array of strings to stop generation (default: `undefined`).
963
+ - `stopSequences` - Array of strings to stop generation.
969
964
  - `forceTools` - Force the model to call one of the provided tools (default: `false`).
970
- - `tools` - Array of `Tool` objects for function calling (default: `undefined`).
965
+ - `telemetryEnabled` - Enable telemetry for this request (default: `true`).
966
+ - `confidenceThreshold` - Confidence threshold below which cloud handoff is triggered (default: `0.7`).
967
+ - `toolRagTopK` - Number of tools to select via RAG when tool list is large (default: `2`).
968
+ - `includeStopSequences` - Whether to include stop sequences in the response (default: `false`).
969
+ - `useVad` - Whether to use VAD preprocessing (default: `true`).
970
+ - `tools` - Array of `CactusLMTool` objects for function calling.
971
971
  - `onToken` - Callback for streaming tokens.
972
- - `mode` - Completion mode: `'local'` | `'hybrid'` (default: `'local'`)
973
972
 
974
973
  **`tokenize(params: CactusLMTokenizeParams): Promise<CactusLMTokenizeResult>`**
975
974
 
@@ -980,7 +979,7 @@ Converts text into tokens using the model's tokenizer.
980
979
 
981
980
  **`scoreWindow(params: CactusLMScoreWindowParams): Promise<CactusLMScoreWindowResult>`**
982
981
 
983
- Calculates perplexity scores for a window of tokens within a sequence.
982
+ Calculates the log-probability score for a window of tokens within a sequence.
984
983
 
985
984
  **Parameters:**
986
985
  - `tokens` - Array of token IDs.
@@ -1015,18 +1014,18 @@ Resets the model's internal state, clearing any cached context. Automatically ca
1015
1014
 
1016
1015
  Releases all resources associated with the model. Automatically calls `stop()` first. Safe to call even if the model is not initialized.
1017
1016
 
1018
- **`getModels(): CactusModel[]`**
1017
+ **`getModels(): Promise<CactusModel[]>`**
1019
1018
 
1020
1019
  Returns available models.
1021
1020
 
1022
1021
  ### useCactusLM Hook
1023
1022
 
1024
- The `useCactusLM` hook manages a `CactusLM` instance with reactive state. When model parameters (`model`, `contextSize`, `corpusDir`, `options`) change, the hook creates a new instance and resets all state. The hook automatically cleans up resources when the component unmounts.
1023
+ The `useCactusLM` hook manages a `CactusLM` instance with reactive state. When model parameters (`model`, `corpusDir`, `cacheIndex`, `options`) change, the hook creates a new instance and resets all state. The hook automatically cleans up resources when the component unmounts.
1025
1024
 
1026
1025
  #### State
1027
1026
 
1028
1027
  - `completion: string` - Current generated text. Automatically accumulated during streaming. Cleared before each new completion and when calling `reset()` or `destroy()`.
1029
- - `isGenerating: boolean` - Whether the model is currently generating (completion or embedding). Both operations share this flag.
1028
+ - `isGenerating: boolean` - Whether the model is currently running an operation. Shared by `complete`, `tokenize`, `scoreWindow`, `embed`, and `imageEmbed`.
1030
1029
  - `isInitializing: boolean` - Whether the model is initializing.
1031
1030
  - `isDownloaded: boolean` - Whether the model is downloaded locally. Automatically checked when the hook mounts or model changes.
1032
1031
  - `isDownloading: boolean` - Whether the model is being downloaded.
@@ -1039,13 +1038,13 @@ The `useCactusLM` hook manages a `CactusLM` instance with reactive state. When m
1039
1038
  - `init(): Promise<void>` - Initializes the model for inference. Sets `isInitializing` to `true` during initialization.
1040
1039
  - `complete(params: CactusLMCompleteParams): Promise<CactusLMCompleteResult>` - Generates text completions. Automatically accumulates tokens in the `completion` state during streaming. Sets `isGenerating` to `true` while generating. Clears `completion` before starting.
1041
1040
  - `tokenize(params: CactusLMTokenizeParams): Promise<CactusLMTokenizeResult>` - Converts text into tokens. Sets `isGenerating` to `true` during operation.
1042
- - `scoreWindow(params: CactusLMScoreWindowParams): Promise<CactusLMScoreWindowResult>` - Calculates perplexity scores for a window of tokens. Sets `isGenerating` to `true` during operation.
1041
+ - `scoreWindow(params: CactusLMScoreWindowParams): Promise<CactusLMScoreWindowResult>` - Calculates log-probability scores for a window of tokens. Sets `isGenerating` to `true` during operation.
1043
1042
  - `embed(params: CactusLMEmbedParams): Promise<CactusLMEmbedResult>` - Generates embeddings for the given text. Sets `isGenerating` to `true` during operation.
1044
1043
  - `imageEmbed(params: CactusLMImageEmbedParams): Promise<CactusLMImageEmbedResult>` - Generates embeddings for the given image. Sets `isGenerating` to `true` while generating.
1045
1044
  - `stop(): Promise<void>` - Stops ongoing generation. Clears any errors.
1046
1045
  - `reset(): Promise<void>` - Resets the model's internal state, clearing cached context. Also clears the `completion` state.
1047
1046
  - `destroy(): Promise<void>` - Releases all resources associated with the model. Clears the `completion` state. Automatically called when the component unmounts.
1048
- - `getModels(): CactusModel[]` - Returns available models.
1047
+ - `getModels(): Promise<CactusModel[]>` - Returns available models.
1049
1048
 
1050
1049
  ### CactusSTT Class
1051
1050
 
@@ -1054,10 +1053,9 @@ The `useCactusLM` hook manages a `CactusLM` instance with reactive state. When m
1054
1053
  **`new CactusSTT(params?: CactusSTTParams)`**
1055
1054
 
1056
1055
  **Parameters:**
1057
- - `model` - Model slug or absolute path to Cactus model (default: `'whisper-small'`).
1058
- - `contextSize` - Context window size (default: `2048`).
1056
+ - `model` - Model slug or absolute path to a model file (default: `'whisper-small'`).
1059
1057
  - `options` - Model options for quantization and NPU acceleration:
1060
- - `quantization` - Quantization type: `'int4'` | `'int8'` (default: `'int4'`).
1058
+ - `quantization` - Quantization type: `'int4'` | `'int8'` (default: `'int8'`).
1061
1059
  - `pro` - Enable NPU-accelerated models (default: `false`).
1062
1060
 
1063
1061
  #### Methods
@@ -1078,49 +1076,47 @@ Initializes the model and prepares it for inference. Safe to call multiple times
1078
1076
  Transcribes audio to text with optional streaming support. Accepts either a file path or raw PCM audio samples. Automatically calls `init()` if not already initialized. Throws an error if a generation is already in progress.
1079
1077
 
1080
1078
  **Parameters:**
1081
- - `audio` - Path to the audio file or raw PCM samples.
1079
+ - `audio` - Path to the audio file or raw PCM samples as a byte array.
1082
1080
  - `prompt` - Optional prompt to guide transcription (default: `'<|startoftranscript|><|en|><|transcribe|><|notimestamps|>'`).
1083
1081
  - `options` - Transcription options:
1084
- - `temperature` - Sampling temperature (default: model-optimized).
1085
- - `topP` - Nucleus sampling threshold (default: model-optimized).
1086
- - `topK` - Top-K sampling limit (default: model-optimized).
1087
- - `maxTokens` - Maximum number of tokens to generate (default: `512`).
1088
- - `stopSequences` - Array of strings to stop generation (default: `undefined`).
1082
+ - `temperature` - Sampling temperature.
1083
+ - `topP` - Nucleus sampling threshold.
1084
+ - `topK` - Top-K sampling limit.
1085
+ - `maxTokens` - Maximum number of tokens to generate (default: `384`).
1086
+ - `stopSequences` - Array of strings to stop generation.
1087
+ - `useVad` - Whether to apply VAD to strip silence before transcription (default: `true`).
1088
+ - `telemetryEnabled` - Enable telemetry for this request (default: `true`).
1089
+ - `confidenceThreshold` - Confidence threshold for quality assessment (default: `0.7`).
1090
+ - `cloudHandoffThreshold` - Max entropy threshold above which cloud handoff is triggered.
1091
+ - `includeStopSequences` - Whether to include stop sequences in the response (default: `false`).
1089
1092
  - `onToken` - Callback for streaming tokens.
1090
1093
 
1091
- **`audioEmbed(params: CactusSTTAudioEmbedParams): Promise<CactusSTTAudioEmbedResult>`**
1094
+ **`streamTranscribeStart(options?: CactusSTTStreamTranscribeStartOptions): Promise<void>`**
1092
1095
 
1093
- Generates embeddings for the given audio file. Automatically calls `init()` if not already initialized. Throws an error if a generation is already in progress.
1096
+ Starts a streaming transcription session. Automatically calls `init()` if not already initialized. If a session is already active, returns immediately.
1094
1097
 
1095
1098
  **Parameters:**
1096
- - `audioPath` - Path to the audio file.
1097
-
1098
- **`streamTranscribeInit(): Promise<void>`**
1099
-
1100
- Initializes a streaming transcription session. Automatically calls `init()` if not already initialized.
1099
+ - `confirmationThreshold` - Fuzzy match ratio required to confirm a transcription segment (default: `0.99`).
1100
+ - `minChunkSize` - Minimum number of audio samples before processing (default: `32000`).
1101
+ - `telemetryEnabled` - Enable telemetry for this session (default: `true`).
1101
1102
 
1102
- **`streamTranscribeInsert(params: CactusSTTStreamTranscribeInsertParams): Promise<void>`**
1103
+ **`streamTranscribeProcess(params: CactusSTTStreamTranscribeProcessParams): Promise<CactusSTTStreamTranscribeProcessResult>`**
1103
1104
 
1104
- Inserts PCM audio samples into the streaming buffer.
1105
+ Feeds audio samples into the streaming session and returns the current transcription state. Throws an error if no session is active.
1105
1106
 
1106
1107
  **Parameters:**
1107
- - `audio` - Array of PCM audio samples.
1108
+ - `audio` - PCM audio samples as a byte array.
1108
1109
 
1109
- **`streamTranscribeProcess(params?: CactusSTTStreamTranscribeProcessParams): Promise<CactusSTTStreamTranscribeProcessResult>`**
1110
-
1111
- Processes accumulated audio and returns incremental transcription results.
1112
-
1113
- **Parameters:**
1114
- - `options` - Processing options:
1115
- - `confirmationThreshold` - Confidence threshold for confirming text.
1110
+ **`streamTranscribeStop(): Promise<CactusSTTStreamTranscribeStopResult>`**
1116
1111
 
1117
- **`streamTranscribeFinalize(): Promise<CactusSTTStreamTranscribeFinalizeResult>`**
1112
+ Stops the streaming session and returns the final confirmed transcription text. Throws an error if no session is active.
1118
1113
 
1119
- Finalizes the streaming session and returns remaining transcription text.
1114
+ **`audioEmbed(params: CactusSTTAudioEmbedParams): Promise<CactusSTTAudioEmbedResult>`**
1120
1115
 
1121
- **`streamTranscribeDestroy(): Promise<void>`**
1116
+ Generates embeddings for the given audio file. Automatically calls `init()` if not already initialized. Throws an error if a generation is already in progress.
1122
1117
 
1123
- Destroys the streaming session and releases resources.
1118
+ **Parameters:**
1119
+ - `audioPath` - Path to the audio file.
1124
1120
 
1125
1121
  **`stop(): Promise<void>`**
1126
1122
 
@@ -1132,23 +1128,23 @@ Resets the model's internal state. Automatically calls `stop()` first.
1132
1128
 
1133
1129
  **`destroy(): Promise<void>`**
1134
1130
 
1135
- Releases all resources associated with the model. Automatically calls `stop()` first. Safe to call even if the model is not initialized.
1131
+ Releases all resources associated with the model. Stops any active streaming session. Automatically calls `stop()` first. Safe to call even if the model is not initialized.
1136
1132
 
1137
- **`getModels(): CactusModel[]`**
1133
+ **`getModels(): Promise<CactusModel[]>`**
1138
1134
 
1139
1135
  Returns available speech-to-text models.
1140
1136
 
1141
1137
  ### useCactusSTT Hook
1142
1138
 
1143
- The `useCactusSTT` hook manages a `CactusSTT` instance with reactive state. When model parameters (`model`, `contextSize`, `options`) change, the hook creates a new instance and resets all state. The hook automatically cleans up resources when the component unmounts.
1139
+ The `useCactusSTT` hook manages a `CactusSTT` instance with reactive state. When model parameters (`model`, `options`) change, the hook creates a new instance and resets all state. The hook automatically cleans up resources when the component unmounts.
1144
1140
 
1145
1141
  #### State
1146
1142
 
1147
1143
  - `transcription: string` - Current transcription text. Automatically accumulated during streaming. Cleared before each new transcription and when calling `reset()` or `destroy()`.
1148
- - `streamTranscribeConfirmed: string` - Accumulated confirmed text from streaming transcription.
1149
- - `streamTranscribePending: string` - Current pending text from streaming transcription.
1150
- - `isGenerating: boolean` - Whether the model is currently generating (transcription or embedding). Both operations share this flag.
1151
- - `isStreamTranscribing: boolean` - Whether a streaming transcription session is active.
1144
+ - `streamTranscribeConfirmed: string` - Accumulated confirmed text from the active streaming session. Updated after each successful `streamTranscribeProcess` call and finalized by `streamTranscribeStop`.
1145
+ - `streamTranscribePending: string` - Uncommitted (in-progress) text from the current audio chunk. Cleared when the session stops.
1146
+ - `isGenerating: boolean` - Whether the model is currently transcribing or embedding. Both operations share this flag.
1147
+ - `isStreamTranscribing: boolean` - Whether a streaming transcription session is currently active.
1152
1148
  - `isInitializing: boolean` - Whether the model is initializing.
1153
1149
  - `isDownloaded: boolean` - Whether the model is downloaded locally. Automatically checked when the hook mounts or model changes.
1154
1150
  - `isDownloading: boolean` - Whether the model is being downloaded.
@@ -1161,15 +1157,84 @@ The `useCactusSTT` hook manages a `CactusSTT` instance with reactive state. When
1161
1157
  - `init(): Promise<void>` - Initializes the model for inference. Sets `isInitializing` to `true` during initialization.
1162
1158
  - `transcribe(params: CactusSTTTranscribeParams): Promise<CactusSTTTranscribeResult>` - Transcribes audio to text. Automatically accumulates tokens in the `transcription` state during streaming. Sets `isGenerating` to `true` while generating. Clears `transcription` before starting.
1163
1159
  - `audioEmbed(params: CactusSTTAudioEmbedParams): Promise<CactusSTTAudioEmbedResult>` - Generates embeddings for the given audio. Sets `isGenerating` to `true` during operation.
1164
- - `streamTranscribeInit(): Promise<void>` - Initializes a streaming transcription session. Sets `isStreamTranscribing` to `true`.
1165
- - `streamTranscribeInsert(params: CactusSTTStreamTranscribeInsertParams): Promise<void>` - Inserts audio chunks into the streaming buffer.
1166
- - `streamTranscribeProcess(params?: CactusSTTStreamTranscribeProcessParams): Promise<CactusSTTStreamTranscribeProcessResult>` - Processes audio and returns results. Automatically accumulates confirmed text in `streamTranscribeConfirmed` and updates `streamTranscribePending`.
1167
- - `streamTranscribeFinalize(): Promise<CactusSTTStreamTranscribeFinalizeResult>` - Finalizes streaming and returns remaining text.
1168
- - `streamTranscribeDestroy(): Promise<void>` - Destroys the streaming session. Sets `isStreamTranscribing` to `false`.
1160
+ - `streamTranscribeStart(options?: CactusSTTStreamTranscribeStartOptions): Promise<void>` - Starts a streaming transcription session. If a session is already active, returns immediately. Clears `streamTranscribeConfirmed` and `streamTranscribePending` before starting. Sets `isStreamTranscribing` to `true`.
1161
+ - `streamTranscribeProcess(params: CactusSTTStreamTranscribeProcessParams): Promise<CactusSTTStreamTranscribeProcessResult>` - Feeds audio and returns incremental results. Appends confirmed text to `streamTranscribeConfirmed` and updates `streamTranscribePending`.
1162
+ - `streamTranscribeStop(): Promise<CactusSTTStreamTranscribeStopResult>` - Stops the session and returns the final result. Sets `isStreamTranscribing` to `false`. Appends final confirmed text to `streamTranscribeConfirmed` and clears `streamTranscribePending`.
1169
1163
  - `stop(): Promise<void>` - Stops ongoing generation. Clears any errors.
1170
1164
  - `reset(): Promise<void>` - Resets the model's internal state. Also clears the `transcription` state.
1171
- - `destroy(): Promise<void>` - Releases all resources associated with the model. Clears the `transcription` state. Automatically called when the component unmounts.
1172
- - `getModels(): CactusModel[]` - Returns available speech-to-text models.
1165
+ - `destroy(): Promise<void>` - Releases all resources associated with the model. Clears the `transcription`, `streamTranscribeConfirmed`, and `streamTranscribePending` state. Automatically called when the component unmounts.
1166
+ - `getModels(): Promise<CactusModel[]>` - Returns available speech-to-text models.
1167
+
1168
+ ### CactusVAD Class
1169
+
1170
+ #### Constructor
1171
+
1172
+ **`new CactusVAD(params?: CactusVADParams)`**
1173
+
1174
+ **Parameters:**
1175
+ - `model` - Model slug or absolute path to a VAD model file (default: `'silero-vad'`).
1176
+ - `options` - Model options:
1177
+ - `quantization` - Quantization type: `'int4'` | `'int8'` (default: `'int8'`).
1178
+ - `pro` - Enable NPU-accelerated models (default: `false`).
1179
+
1180
+ #### Methods
1181
+
1182
+ **`download(params?: CactusVADDownloadParams): Promise<void>`**
1183
+
1184
+ Downloads the VAD model. If the model is already downloaded, returns immediately with progress `1`. Throws an error if a download is already in progress.
1185
+
1186
+ **Parameters:**
1187
+ - `onProgress` - Callback for download progress (0-1).
1188
+
1189
+ **`init(): Promise<void>`**
1190
+
1191
+ Initializes the VAD model. Safe to call multiple times (idempotent). Throws an error if the model is not downloaded yet.
1192
+
1193
+ **`vad(params: CactusVADVadParams): Promise<CactusVADResult>`**
1194
+
1195
+ Runs voice activity detection on the given audio. Automatically calls `init()` if not already initialized.
1196
+
1197
+ **Parameters:**
1198
+ - `audio` - Path to the audio file or raw PCM samples as a byte array.
1199
+ - `options` - VAD options:
1200
+ - `threshold` - Speech probability threshold (default: model default).
1201
+ - `negThreshold` - Silence probability threshold.
1202
+ - `minSpeechDurationMs` - Minimum speech segment duration in ms.
1203
+ - `maxSpeechDurationS` - Maximum speech segment duration in seconds.
1204
+ - `minSilenceDurationMs` - Minimum silence duration before ending a segment.
1205
+ - `speechPadMs` - Padding added to each speech segment in ms.
1206
+ - `windowSizeSamples` - Processing window size in samples.
1207
+ - `samplingRate` - Audio sampling rate.
1208
+ - `minSilenceAtMaxSpeech` - Minimum silence at max speech duration.
1209
+ - `useMaxPossSilAtMaxSpeech` - Whether to use maximum possible silence at max speech.
1210
+
1211
+ **`destroy(): Promise<void>`**
1212
+
1213
+ Releases all resources associated with the model. Safe to call even if the model is not initialized.
1214
+
1215
+ **`getModels(): Promise<CactusModel[]>`**
1216
+
1217
+ Returns available VAD models.
1218
+
1219
+ ### useCactusVAD Hook
1220
+
1221
+ The `useCactusVAD` hook manages a `CactusVAD` instance with reactive state. When model parameters (`model`, `options`) change, the hook creates a new instance and resets all state. The hook automatically cleans up resources when the component unmounts.
1222
+
1223
+ #### State
1224
+
1225
+ - `isInitializing: boolean` - Whether the model is initializing.
1226
+ - `isDownloaded: boolean` - Whether the model is downloaded locally. Automatically checked when the hook mounts or model changes.
1227
+ - `isDownloading: boolean` - Whether the model is being downloaded.
1228
+ - `downloadProgress: number` - Download progress (0-1). Reset to `0` after download completes.
1229
+ - `error: string | null` - Last error message, or `null`.
1230
+
1231
+ #### Methods
1232
+
1233
+ - `download(params?: CactusVADDownloadParams): Promise<void>` - Downloads the model. Updates `isDownloading` and `downloadProgress` state during download. Sets `isDownloaded` to `true` on success.
1234
+ - `init(): Promise<void>` - Initializes the model.
1235
+ - `vad(params: CactusVADVadParams): Promise<CactusVADResult>` - Runs voice activity detection.
1236
+ - `destroy(): Promise<void>` - Releases all resources. Automatically called when the component unmounts.
1237
+ - `getModels(): Promise<CactusModel[]>` - Returns available VAD models.
1173
1238
 
1174
1239
  ### CactusIndex Class
1175
1240
 
@@ -1256,9 +1321,9 @@ The `useCactusIndex` hook manages a `CactusIndex` instance with reactive state.
1256
1321
  ```typescript
1257
1322
  interface CactusLMParams {
1258
1323
  model?: string;
1259
- contextSize?: number;
1260
1324
  corpusDir?: string;
1261
- options?: ModelOptions;
1325
+ cacheIndex?: boolean;
1326
+ options?: CactusModelOptions;
1262
1327
  }
1263
1328
  ```
1264
1329
 
@@ -1270,33 +1335,38 @@ interface CactusLMDownloadParams {
1270
1335
  }
1271
1336
  ```
1272
1337
 
1273
- ### Message
1338
+ ### CactusLMMessage
1274
1339
 
1275
1340
  ```typescript
1276
- interface Message {
1341
+ interface CactusLMMessage {
1277
1342
  role: 'user' | 'assistant' | 'system';
1278
1343
  content?: string;
1279
1344
  images?: string[];
1280
1345
  }
1281
1346
  ```
1282
1347
 
1283
- ### CompleteOptions
1348
+ ### CactusLMCompleteOptions
1284
1349
 
1285
1350
  ```typescript
1286
- interface CompleteOptions {
1351
+ interface CactusLMCompleteOptions {
1287
1352
  temperature?: number;
1288
1353
  topP?: number;
1289
1354
  topK?: number;
1290
1355
  maxTokens?: number;
1291
1356
  stopSequences?: string[];
1292
1357
  forceTools?: boolean;
1358
+ telemetryEnabled?: boolean;
1359
+ confidenceThreshold?: number;
1360
+ toolRagTopK?: number;
1361
+ includeStopSequences?: boolean;
1362
+ useVad?: boolean;
1293
1363
  }
1294
1364
  ```
1295
1365
 
1296
- ### Tool
1366
+ ### CactusLMTool
1297
1367
 
1298
1368
  ```typescript
1299
- interface Tool {
1369
+ interface CactusLMTool {
1300
1370
  name: string;
1301
1371
  description: string;
1302
1372
  parameters: {
@@ -1316,11 +1386,10 @@ interface Tool {
1316
1386
 
1317
1387
  ```typescript
1318
1388
  interface CactusLMCompleteParams {
1319
- messages: Message[];
1320
- options?: CompleteOptions;
1321
- tools?: Tool[];
1389
+ messages: CactusLMMessage[];
1390
+ options?: CactusLMCompleteOptions;
1391
+ tools?: CactusLMTool[];
1322
1392
  onToken?: (token: string) => void;
1323
- mode?: 'local' | 'hybrid';
1324
1393
  }
1325
1394
  ```
1326
1395
 
@@ -1334,12 +1403,16 @@ interface CactusLMCompleteResult {
1334
1403
  name: string;
1335
1404
  arguments: { [key: string]: any };
1336
1405
  }[];
1406
+ cloudHandoff?: boolean;
1407
+ confidence?: number;
1337
1408
  timeToFirstTokenMs: number;
1338
1409
  totalTimeMs: number;
1339
- tokensPerSecond: number;
1340
1410
  prefillTokens: number;
1411
+ prefillTps: number;
1341
1412
  decodeTokens: number;
1413
+ decodeTps: number;
1342
1414
  totalTokens: number;
1415
+ ramUsageMb?: number;
1343
1416
  }
1344
1417
  ```
1345
1418
 
@@ -1415,11 +1488,6 @@ interface CactusLMImageEmbedResult {
1415
1488
 
1416
1489
  ```typescript
1417
1490
  interface CactusModel {
1418
- completion: boolean;
1419
- tools: boolean;
1420
- vision: boolean;
1421
- embed: boolean;
1422
- speech: boolean;
1423
1491
  quantization: {
1424
1492
  int4: {
1425
1493
  sizeMb: number;
@@ -1439,12 +1507,12 @@ interface CactusModel {
1439
1507
  }
1440
1508
  ```
1441
1509
 
1442
- ### ModelOptions
1510
+ ### CactusModelOptions
1443
1511
 
1444
1512
  ```typescript
1445
- interface ModelOptions {
1446
- quantization: 'int4' | 'int8';
1447
- pro: boolean;
1513
+ interface CactusModelOptions {
1514
+ quantization?: 'int4' | 'int8';
1515
+ pro?: boolean;
1448
1516
  }
1449
1517
  ```
1450
1518
 
@@ -1453,8 +1521,7 @@ interface ModelOptions {
1453
1521
  ```typescript
1454
1522
  interface CactusSTTParams {
1455
1523
  model?: string;
1456
- contextSize?: number;
1457
- options?: ModelOptions;
1524
+ options?: CactusModelOptions;
1458
1525
  }
1459
1526
  ```
1460
1527
 
@@ -1464,18 +1531,22 @@ interface CactusSTTParams {
1464
1531
  interface CactusSTTDownloadParams {
1465
1532
  onProgress?: (progress: number) => void;
1466
1533
  }
1467
-
1468
1534
  ```
1469
1535
 
1470
- ### TranscribeOptions
1536
+ ### CactusSTTTranscribeOptions
1471
1537
 
1472
- ```ts
1473
- interface TranscribeOptions {
1538
+ ```typescript
1539
+ interface CactusSTTTranscribeOptions {
1474
1540
  temperature?: number;
1475
1541
  topP?: number;
1476
1542
  topK?: number;
1477
1543
  maxTokens?: number;
1478
1544
  stopSequences?: string[];
1545
+ useVad?: boolean;
1546
+ telemetryEnabled?: boolean;
1547
+ confidenceThreshold?: number;
1548
+ cloudHandoffThreshold?: number;
1549
+ includeStopSequences?: boolean;
1479
1550
  }
1480
1551
  ```
1481
1552
 
@@ -1485,7 +1556,7 @@ interface TranscribeOptions {
1485
1556
  interface CactusSTTTranscribeParams {
1486
1557
  audio: string | number[];
1487
1558
  prompt?: string;
1488
- options?: TranscribeOptions;
1559
+ options?: CactusSTTTranscribeOptions;
1489
1560
  onToken?: (token: string) => void;
1490
1561
  }
1491
1562
  ```
@@ -1496,14 +1567,17 @@ interface CactusSTTTranscribeParams {
1496
1567
  interface CactusSTTTranscribeResult {
1497
1568
  success: boolean;
1498
1569
  response: string;
1570
+ cloudHandoff?: boolean;
1571
+ confidence?: number;
1499
1572
  timeToFirstTokenMs: number;
1500
1573
  totalTimeMs: number;
1501
- tokensPerSecond: number;
1502
1574
  prefillTokens: number;
1575
+ prefillTps: number;
1503
1576
  decodeTokens: number;
1577
+ decodeTps: number;
1504
1578
  totalTokens: number;
1579
+ ramUsageMb?: number;
1505
1580
  }
1506
-
1507
1581
  ```
1508
1582
 
1509
1583
  ### CactusSTTAudioEmbedParams
@@ -1522,19 +1596,13 @@ interface CactusSTTAudioEmbedResult {
1522
1596
  }
1523
1597
  ```
1524
1598
 
1525
- ### CactusSTTStreamTranscribeInsertParams
1599
+ ### CactusSTTStreamTranscribeStartOptions
1526
1600
 
1527
1601
  ```typescript
1528
- interface CactusSTTStreamTranscribeInsertParams {
1529
- audio: number[];
1530
- }
1531
- ```
1532
-
1533
- ### StreamTranscribeProcessOptions
1534
-
1535
- ```typescript
1536
- interface StreamTranscribeProcessOptions {
1602
+ interface CactusSTTStreamTranscribeStartOptions {
1537
1603
  confirmationThreshold?: number;
1604
+ minChunkSize?: number;
1605
+ telemetryEnabled?: boolean;
1538
1606
  }
1539
1607
  ```
1540
1608
 
@@ -1542,7 +1610,7 @@ interface StreamTranscribeProcessOptions {
1542
1610
 
1543
1611
  ```typescript
1544
1612
  interface CactusSTTStreamTranscribeProcessParams {
1545
- options?: StreamTranscribeProcessOptions;
1613
+ audio: number[];
1546
1614
  }
1547
1615
  ```
1548
1616
 
@@ -1553,18 +1621,94 @@ interface CactusSTTStreamTranscribeProcessResult {
1553
1621
  success: boolean;
1554
1622
  confirmed: string;
1555
1623
  pending: string;
1624
+ bufferDurationMs?: number;
1625
+ confidence?: number;
1626
+ cloudHandoff?: boolean;
1627
+ cloudResult?: string;
1628
+ cloudJobId?: number;
1629
+ cloudResultJobId?: number;
1630
+ timeToFirstTokenMs?: number;
1631
+ totalTimeMs?: number;
1632
+ prefillTokens?: number;
1633
+ prefillTps?: number;
1634
+ decodeTokens?: number;
1635
+ decodeTps?: number;
1636
+ totalTokens?: number;
1637
+ ramUsageMb?: number;
1556
1638
  }
1557
1639
  ```
1558
1640
 
1559
- ### CactusSTTStreamTranscribeFinalizeResult
1641
+ ### CactusSTTStreamTranscribeStopResult
1560
1642
 
1561
1643
  ```typescript
1562
- interface CactusSTTStreamTranscribeFinalizeResult {
1644
+ interface CactusSTTStreamTranscribeStopResult {
1563
1645
  success: boolean;
1564
1646
  confirmed: string;
1565
1647
  }
1566
1648
  ```
1567
1649
 
1650
+ ### CactusVADParams
1651
+
1652
+ ```typescript
1653
+ interface CactusVADParams {
1654
+ model?: string;
1655
+ options?: CactusModelOptions;
1656
+ }
1657
+ ```
1658
+
1659
+ ### CactusVADDownloadParams
1660
+
1661
+ ```typescript
1662
+ interface CactusVADDownloadParams {
1663
+ onProgress?: (progress: number) => void;
1664
+ }
1665
+ ```
1666
+
1667
+ ### CactusVADOptions
1668
+
1669
+ ```typescript
1670
+ interface CactusVADOptions {
1671
+ threshold?: number;
1672
+ negThreshold?: number;
1673
+ minSpeechDurationMs?: number;
1674
+ maxSpeechDurationS?: number;
1675
+ minSilenceDurationMs?: number;
1676
+ speechPadMs?: number;
1677
+ windowSizeSamples?: number;
1678
+ samplingRate?: number;
1679
+ minSilenceAtMaxSpeech?: number;
1680
+ useMaxPossSilAtMaxSpeech?: boolean;
1681
+ }
1682
+ ```
1683
+
1684
+ ### CactusVADSegment
1685
+
1686
+ ```typescript
1687
+ interface CactusVADSegment {
1688
+ start: number;
1689
+ end: number;
1690
+ }
1691
+ ```
1692
+
1693
+ ### CactusVADResult
1694
+
1695
+ ```typescript
1696
+ interface CactusVADResult {
1697
+ segments: CactusVADSegment[];
1698
+ totalTime: number;
1699
+ ramUsage: number;
1700
+ }
1701
+ ```
1702
+
1703
+ ### CactusVADVadParams
1704
+
1705
+ ```typescript
1706
+ interface CactusVADVadParams {
1707
+ audio: string | number[];
1708
+ options?: CactusVADOptions;
1709
+ }
1710
+ ```
1711
+
1568
1712
  ### CactusIndexParams
1569
1713
 
1570
1714
  ```typescript
@@ -1603,10 +1747,10 @@ interface CactusIndexGetResult {
1603
1747
  }
1604
1748
  ```
1605
1749
 
1606
- ### IndexQueryOptions
1750
+ ### CactusIndexQueryOptions
1607
1751
 
1608
1752
  ```typescript
1609
- interface IndexQueryOptions {
1753
+ interface CactusIndexQueryOptions {
1610
1754
  topK?: number;
1611
1755
  scoreThreshold?: number;
1612
1756
  }
@@ -1617,7 +1761,7 @@ interface IndexQueryOptions {
1617
1761
  ```typescript
1618
1762
  interface CactusIndexQueryParams {
1619
1763
  embeddings: number[][];
1620
- options?: IndexQueryOptions;
1764
+ options?: CactusIndexQueryOptions;
1621
1765
  }
1622
1766
  ```
1623
1767
 
@@ -1638,49 +1782,11 @@ interface CactusIndexDeleteParams {
1638
1782
  }
1639
1783
  ```
1640
1784
 
1641
- ## Configuration
1642
-
1643
- ### Telemetry
1644
-
1645
- Cactus offers powerful telemetry for all your projects. Create a token on the [Cactus dashboard](https://www.cactuscompute.com/dashboard).
1646
-
1647
- ```typescript
1648
- import { CactusConfig } from 'cactus-react-native';
1649
-
1650
- // Enable Telemetry for your project
1651
- CactusConfig.telemetryToken = 'your-telemetry-token-here';
1652
-
1653
- // Disable telemetry
1654
- CactusConfig.isTelemetryEnabled = false;
1655
- ```
1656
-
1657
- ### Hybrid Mode
1658
-
1659
- Enable cloud fallback.
1660
-
1661
- ```typescript
1662
- import { CactusConfig } from 'cactus-react-native';
1663
-
1664
- // Set your Cactus token for hybrid mode
1665
- CactusConfig.cactusToken = 'your-cactus-token-here';
1666
- ```
1667
-
1668
- ### Cactus Pro
1669
-
1670
- Enable NPU-accelerated models for enhanced performance.
1671
-
1672
- ```typescript
1673
- import { CactusConfig } from 'cactus-react-native';
1674
-
1675
- // Set your Cactus Pro key
1676
- CactusConfig.cactusProKey = 'your-cactus-pro-key-here';
1677
- ```
1678
-
1679
1785
  ## Performance Tips
1680
1786
 
1681
1787
  - **Model Selection** - Choose smaller models for faster inference on mobile devices.
1682
- - **Context Size** - Reduce the context size to lower memory usage.
1683
1788
  - **Memory Management** - Always call `destroy()` when you're done with models to free up resources.
1789
+ - **VAD** - Use `useVad: true` (the default) when transcribing audio with silence, to strip non-speech regions and speed up transcription.
1684
1790
 
1685
1791
  ## Example App
1686
1792