cactus-react-native 1.0.2 → 1.2.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 (126) hide show
  1. package/README.md +378 -21
  2. package/android/src/main/java/com/margelo/nitro/cactus/HybridCactusCrypto.kt +23 -15
  3. package/android/src/main/java/com/margelo/nitro/cactus/HybridCactusDeviceInfo.kt +12 -9
  4. package/android/src/main/java/com/margelo/nitro/cactus/HybridCactusFileSystem.kt +42 -41
  5. package/android/src/main/java/com/margelo/nitro/cactus/HybridCactusImage.kt +81 -0
  6. package/android/src/main/jniLibs/arm64-v8a/libcactus.a +0 -0
  7. package/cpp/HybridCactus.cpp +105 -0
  8. package/cpp/HybridCactus.hpp +13 -0
  9. package/cpp/cactus_ffi.h +27 -0
  10. package/ios/HybridCactusImage.swift +53 -0
  11. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/cactus_ffi.h +27 -0
  12. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/engine.h +37 -5
  13. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ffi_utils.h +10 -9
  14. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/graph.h +49 -7
  15. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/kernel.h +31 -0
  16. package/ios/cactus.xcframework/ios-arm64/cactus.framework/cactus +0 -0
  17. package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/cactus_ffi.h +27 -0
  18. package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/engine.h +37 -5
  19. package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/ffi_utils.h +10 -9
  20. package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/graph.h +49 -7
  21. package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/kernel.h +31 -0
  22. package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/cactus +0 -0
  23. package/lib/module/api/Database.js +23 -0
  24. package/lib/module/api/Database.js.map +1 -1
  25. package/lib/module/api/RemoteLM.js +201 -0
  26. package/lib/module/api/RemoteLM.js.map +1 -0
  27. package/lib/module/classes/CactusLM.js +52 -26
  28. package/lib/module/classes/CactusLM.js.map +1 -1
  29. package/lib/module/classes/CactusSTT.js +139 -0
  30. package/lib/module/classes/CactusSTT.js.map +1 -0
  31. package/lib/module/config/CactusConfig.js +4 -0
  32. package/lib/module/config/CactusConfig.js.map +1 -1
  33. package/lib/module/constants/packageVersion.js +1 -1
  34. package/lib/module/hooks/useCactusLM.js +33 -10
  35. package/lib/module/hooks/useCactusLM.js.map +1 -1
  36. package/lib/module/hooks/useCactusSTT.js +234 -0
  37. package/lib/module/hooks/useCactusSTT.js.map +1 -0
  38. package/lib/module/index.js +2 -0
  39. package/lib/module/index.js.map +1 -1
  40. package/lib/module/native/Cactus.js +50 -1
  41. package/lib/module/native/Cactus.js.map +1 -1
  42. package/lib/module/native/CactusFileSystem.js +2 -3
  43. package/lib/module/native/CactusFileSystem.js.map +1 -1
  44. package/lib/module/native/CactusImage.js +13 -0
  45. package/lib/module/native/CactusImage.js.map +1 -0
  46. package/lib/module/native/index.js +1 -0
  47. package/lib/module/native/index.js.map +1 -1
  48. package/lib/module/specs/CactusImage.nitro.js +4 -0
  49. package/lib/module/specs/CactusImage.nitro.js.map +1 -0
  50. package/lib/module/telemetry/Telemetry.js +53 -1
  51. package/lib/module/telemetry/Telemetry.js.map +1 -1
  52. package/lib/module/types/CactusSTT.js +2 -0
  53. package/lib/module/types/CactusSTT.js.map +1 -0
  54. package/lib/typescript/src/api/Database.d.ts +1 -0
  55. package/lib/typescript/src/api/Database.d.ts.map +1 -1
  56. package/lib/typescript/src/api/RemoteLM.d.ts +14 -0
  57. package/lib/typescript/src/api/RemoteLM.d.ts.map +1 -0
  58. package/lib/typescript/src/classes/CactusLM.d.ts +6 -4
  59. package/lib/typescript/src/classes/CactusLM.d.ts.map +1 -1
  60. package/lib/typescript/src/classes/CactusSTT.d.ts +26 -0
  61. package/lib/typescript/src/classes/CactusSTT.d.ts.map +1 -0
  62. package/lib/typescript/src/config/CactusConfig.d.ts +1 -0
  63. package/lib/typescript/src/config/CactusConfig.d.ts.map +1 -1
  64. package/lib/typescript/src/constants/packageVersion.d.ts +1 -1
  65. package/lib/typescript/src/hooks/useCactusLM.d.ts +4 -3
  66. package/lib/typescript/src/hooks/useCactusLM.d.ts.map +1 -1
  67. package/lib/typescript/src/hooks/useCactusSTT.d.ts +20 -0
  68. package/lib/typescript/src/hooks/useCactusSTT.d.ts.map +1 -0
  69. package/lib/typescript/src/index.d.ts +4 -1
  70. package/lib/typescript/src/index.d.ts.map +1 -1
  71. package/lib/typescript/src/native/Cactus.d.ts +9 -2
  72. package/lib/typescript/src/native/Cactus.d.ts.map +1 -1
  73. package/lib/typescript/src/native/CactusFileSystem.d.ts +1 -1
  74. package/lib/typescript/src/native/CactusFileSystem.d.ts.map +1 -1
  75. package/lib/typescript/src/native/CactusImage.d.ts +6 -0
  76. package/lib/typescript/src/native/CactusImage.d.ts.map +1 -0
  77. package/lib/typescript/src/native/index.d.ts +1 -0
  78. package/lib/typescript/src/native/index.d.ts.map +1 -1
  79. package/lib/typescript/src/specs/Cactus.nitro.d.ts +3 -0
  80. package/lib/typescript/src/specs/Cactus.nitro.d.ts.map +1 -1
  81. package/lib/typescript/src/specs/CactusImage.nitro.d.ts +9 -0
  82. package/lib/typescript/src/specs/CactusImage.nitro.d.ts.map +1 -0
  83. package/lib/typescript/src/telemetry/Telemetry.d.ts +5 -1
  84. package/lib/typescript/src/telemetry/Telemetry.d.ts.map +1 -1
  85. package/lib/typescript/src/types/CactusLM.d.ts +8 -5
  86. package/lib/typescript/src/types/CactusLM.d.ts.map +1 -1
  87. package/lib/typescript/src/types/CactusSTT.d.ts +37 -0
  88. package/lib/typescript/src/types/CactusSTT.d.ts.map +1 -0
  89. package/nitro.json +4 -0
  90. package/nitrogen/generated/android/c++/JHybridCactusImageSpec.cpp +81 -0
  91. package/nitrogen/generated/android/c++/JHybridCactusImageSpec.hpp +66 -0
  92. package/nitrogen/generated/android/cactus+autolinking.cmake +2 -0
  93. package/nitrogen/generated/android/cactusOnLoad.cpp +10 -0
  94. package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/HybridCactusImageSpec.kt +62 -0
  95. package/nitrogen/generated/ios/Cactus-Swift-Cxx-Bridge.cpp +17 -0
  96. package/nitrogen/generated/ios/Cactus-Swift-Cxx-Bridge.hpp +17 -0
  97. package/nitrogen/generated/ios/Cactus-Swift-Cxx-Umbrella.hpp +5 -0
  98. package/nitrogen/generated/ios/CactusAutolinking.mm +8 -0
  99. package/nitrogen/generated/ios/CactusAutolinking.swift +15 -0
  100. package/nitrogen/generated/ios/c++/HybridCactusImageSpecSwift.cpp +11 -0
  101. package/nitrogen/generated/ios/c++/HybridCactusImageSpecSwift.hpp +85 -0
  102. package/nitrogen/generated/ios/swift/HybridCactusImageSpec.swift +58 -0
  103. package/nitrogen/generated/ios/swift/HybridCactusImageSpec_cxx.swift +158 -0
  104. package/nitrogen/generated/shared/c++/HybridCactusImageSpec.cpp +22 -0
  105. package/nitrogen/generated/shared/c++/HybridCactusImageSpec.hpp +64 -0
  106. package/nitrogen/generated/shared/c++/HybridCactusSpec.cpp +3 -0
  107. package/nitrogen/generated/shared/c++/HybridCactusSpec.hpp +3 -0
  108. package/package.json +1 -1
  109. package/src/api/Database.ts +27 -0
  110. package/src/api/RemoteLM.ts +273 -0
  111. package/src/classes/CactusLM.ts +72 -38
  112. package/src/classes/CactusSTT.ts +188 -0
  113. package/src/config/CactusConfig.ts +4 -0
  114. package/src/constants/packageVersion.ts +1 -1
  115. package/src/hooks/useCactusLM.ts +45 -17
  116. package/src/hooks/useCactusSTT.ts +285 -0
  117. package/src/index.tsx +14 -2
  118. package/src/native/Cactus.ts +94 -4
  119. package/src/native/CactusFileSystem.ts +2 -2
  120. package/src/native/CactusImage.ts +20 -0
  121. package/src/native/index.ts +1 -0
  122. package/src/specs/Cactus.nitro.ts +9 -0
  123. package/src/specs/CactusImage.nitro.ts +12 -0
  124. package/src/telemetry/Telemetry.ts +78 -1
  125. package/src/types/CactusLM.ts +9 -5
  126. package/src/types/CactusSTT.ts +42 -0
@@ -8,6 +8,7 @@ import {
8
8
  import { CactusConfig } from '../config/CactusConfig';
9
9
  import { packageVersion } from '../constants/packageVersion';
10
10
  import type { CactusLMCompleteResult } from '../types/CactusLM';
11
+ import type { CactusSTTTranscribeResult } from '../types/CactusSTT';
11
12
 
12
13
  export interface LogRecord {
13
14
  // Framework
@@ -15,7 +16,13 @@ export interface LogRecord {
15
16
  framework_version: string;
16
17
 
17
18
  // Event
18
- event_type: 'init' | 'completion' | 'embedding';
19
+ event_type:
20
+ | 'init'
21
+ | 'completion'
22
+ | 'transcription'
23
+ | 'embedding'
24
+ | 'image_embedding'
25
+ | 'audio_embedding';
19
26
  model: string;
20
27
  success: boolean;
21
28
  message?: string;
@@ -41,10 +48,17 @@ export class Telemetry {
41
48
  private static readonly logBufferPaths = {
42
49
  init: 'logs/init.json',
43
50
  completion: 'logs/completion.json',
51
+ transcription: 'logs/transcription.json',
44
52
  embedding: 'logs/embedding.json',
53
+ image_embedding: 'logs/image_embedding.json',
54
+ audio_embedding: 'logs/audio_embedding.json',
45
55
  };
46
56
 
47
57
  private static async handleLog(logRecord: LogRecord) {
58
+ if (!this.isInitialized()) {
59
+ return;
60
+ }
61
+
48
62
  if (!CactusConfig.isTelemetryEnabled) {
49
63
  return;
50
64
  }
@@ -78,6 +92,10 @@ export class Telemetry {
78
92
  }
79
93
 
80
94
  public static async init(cactusTelemetryToken?: string): Promise<void> {
95
+ if (this.isInitialized()) {
96
+ return;
97
+ }
98
+
81
99
  if (!CactusConfig.isTelemetryEnabled) {
82
100
  return;
83
101
  }
@@ -139,6 +157,29 @@ export class Telemetry {
139
157
  });
140
158
  }
141
159
 
160
+ public static logTranscribe(
161
+ model: string,
162
+ success: boolean,
163
+ message?: string,
164
+ result?: CactusSTTTranscribeResult
165
+ ): Promise<void> {
166
+ return this.handleLog({
167
+ framework: 'react-native',
168
+ framework_version: packageVersion,
169
+ event_type: 'transcription',
170
+ model,
171
+ success,
172
+ message,
173
+ telemetry_token: this.cactusTelemetryToken,
174
+ project_id: this.projectId,
175
+ device_id: this.deviceId,
176
+ tokens: result?.totalTokens,
177
+ response_time: result?.totalTimeMs,
178
+ ttft: result?.timeToFirstTokenMs,
179
+ tps: result?.tokensPerSecond,
180
+ });
181
+ }
182
+
142
183
  public static logEmbedding(
143
184
  model: string,
144
185
  success: boolean,
@@ -156,4 +197,40 @@ export class Telemetry {
156
197
  device_id: this.deviceId,
157
198
  });
158
199
  }
200
+
201
+ public static logImageEmbedding(
202
+ model: string,
203
+ success: boolean,
204
+ message?: string
205
+ ): Promise<void> {
206
+ return this.handleLog({
207
+ framework: 'react-native',
208
+ framework_version: packageVersion,
209
+ event_type: 'image_embedding',
210
+ model,
211
+ success,
212
+ message,
213
+ telemetry_token: this.cactusTelemetryToken,
214
+ project_id: this.projectId,
215
+ device_id: this.deviceId,
216
+ });
217
+ }
218
+
219
+ public static logAudioEmbedding(
220
+ model: string,
221
+ success: boolean,
222
+ message?: string
223
+ ): Promise<void> {
224
+ return this.handleLog({
225
+ framework: 'react-native',
226
+ framework_version: packageVersion,
227
+ event_type: 'audio_embedding',
228
+ model,
229
+ success,
230
+ message,
231
+ telemetry_token: this.cactusTelemetryToken,
232
+ project_id: this.projectId,
233
+ device_id: this.deviceId,
234
+ });
235
+ }
159
236
  }
@@ -14,7 +14,7 @@ export interface Message {
14
14
  images?: string[];
15
15
  }
16
16
 
17
- export interface Options {
17
+ export interface CompleteOptions {
18
18
  temperature?: number;
19
19
  topP?: number;
20
20
  topK?: number;
@@ -23,7 +23,6 @@ export interface Options {
23
23
  }
24
24
 
25
25
  export interface Tool {
26
- type: 'function';
27
26
  name: string;
28
27
  description: string;
29
28
  parameters: {
@@ -40,9 +39,10 @@ export interface Tool {
40
39
 
41
40
  export interface CactusLMCompleteParams {
42
41
  messages: Message[];
43
- options?: Options;
42
+ options?: CompleteOptions;
44
43
  tools?: Tool[];
45
44
  onToken?: (token: string) => void;
45
+ mode?: 'local' | 'hybrid';
46
46
  }
47
47
 
48
48
  export interface CactusLMCompleteResult {
@@ -68,6 +68,10 @@ export interface CactusLMEmbedResult {
68
68
  embedding: number[];
69
69
  }
70
70
 
71
- export interface CactusLMGetModelsParams {
72
- forceRefresh?: boolean;
71
+ export interface CactusLMImageEmbedParams {
72
+ imagePath: string;
73
+ }
74
+
75
+ export interface CactusLMImageEmbedResult {
76
+ embedding: number[];
73
77
  }
@@ -0,0 +1,42 @@
1
+ export interface CactusSTTParams {
2
+ model?: string;
3
+ contextSize?: number;
4
+ }
5
+
6
+ export interface CactusSTTDownloadParams {
7
+ onProgress?: (progress: number) => void;
8
+ }
9
+
10
+ export interface TranscribeOptions {
11
+ temperature?: number;
12
+ topP?: number;
13
+ topK?: number;
14
+ maxTokens?: number;
15
+ stopSequences?: string[];
16
+ }
17
+
18
+ export interface CactusSTTTranscribeParams {
19
+ audioFilePath: string;
20
+ prompt?: string;
21
+ options?: TranscribeOptions;
22
+ onToken?: (token: string) => void;
23
+ }
24
+
25
+ export interface CactusSTTTranscribeResult {
26
+ success: boolean;
27
+ response: string;
28
+ timeToFirstTokenMs: number;
29
+ totalTimeMs: number;
30
+ tokensPerSecond: number;
31
+ prefillTokens: number;
32
+ decodeTokens: number;
33
+ totalTokens: number;
34
+ }
35
+
36
+ export interface CactusSTTAudioEmbedParams {
37
+ audioPath: string;
38
+ }
39
+
40
+ export interface CactusSTTAudioEmbedResult {
41
+ embedding: number[];
42
+ }