@functionland/react-native-fula 1.55.0 → 1.55.2

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 (98) hide show
  1. package/LICENSE +20 -20
  2. package/android/build.gradle +114 -115
  3. package/android/gradle.properties +8 -8
  4. package/android/src/main/AndroidManifest.xml +3 -3
  5. package/android/src/main/AndroidManifestNew.xml +2 -2
  6. package/android/src/main/java/land/fx/fula/ConfigRef.java +7 -7
  7. package/android/src/main/java/land/fx/fula/Cryptography.java +62 -62
  8. package/android/src/main/java/land/fx/fula/FulaModule.java +1991 -1868
  9. package/android/src/main/java/land/fx/fula/FulaPackage.java +32 -32
  10. package/android/src/main/java/land/fx/fula/SharedPreferenceHelper.java +65 -65
  11. package/android/src/main/java/land/fx/fula/StaticHelper.java +13 -13
  12. package/android/src/main/java/land/fx/fula/ThreadUtils.java +42 -42
  13. package/ios/Cryptography.swift +59 -59
  14. package/ios/Fula-Bridging-Header.h +3 -3
  15. package/ios/UserDataHelper.swift +143 -143
  16. package/lib/commonjs/index.js +3 -1
  17. package/lib/commonjs/index.js.map +1 -1
  18. package/lib/commonjs/interfaces/augment-api-consts.js.map +1 -1
  19. package/lib/commonjs/interfaces/augment-api-errors.js.map +1 -1
  20. package/lib/commonjs/interfaces/augment-api-events.js.map +1 -1
  21. package/lib/commonjs/interfaces/augment-api-query.js.map +1 -1
  22. package/lib/commonjs/interfaces/augment-api-rpc.js.map +1 -1
  23. package/lib/commonjs/interfaces/augment-api-runtime.js.map +1 -1
  24. package/lib/commonjs/interfaces/augment-api-tx.js.map +1 -1
  25. package/lib/commonjs/interfaces/augment-api.js.map +1 -1
  26. package/lib/commonjs/interfaces/augment-types.js.map +1 -1
  27. package/lib/commonjs/interfaces/definitions.js.map +1 -1
  28. package/lib/commonjs/interfaces/defintions.js.map +1 -1
  29. package/lib/commonjs/interfaces/fulaNativeModule.js.map +1 -1
  30. package/lib/commonjs/interfaces/index.js.map +1 -1
  31. package/lib/commonjs/interfaces/lookup.js +300 -300
  32. package/lib/commonjs/interfaces/lookup.js.map +1 -1
  33. package/lib/commonjs/interfaces/registry.js.map +1 -1
  34. package/lib/commonjs/interfaces/types-lookup.js.map +1 -1
  35. package/lib/commonjs/interfaces/types.js.map +1 -1
  36. package/lib/commonjs/protocols/blockchain.js +66 -66
  37. package/lib/commonjs/protocols/blockchain.js.map +1 -1
  38. package/lib/commonjs/protocols/chain-api.js.map +1 -1
  39. package/lib/commonjs/protocols/fula.js.map +1 -1
  40. package/lib/commonjs/protocols/fx-ai.js +161 -0
  41. package/lib/commonjs/protocols/fx-ai.js.map +1 -0
  42. package/lib/commonjs/protocols/fxblox.js +3 -3
  43. package/lib/commonjs/protocols/fxblox.js.map +1 -1
  44. package/lib/commonjs/types/blockchain.js.map +1 -1
  45. package/lib/commonjs/types/fxblox.js.map +1 -1
  46. package/lib/module/index.js +1 -0
  47. package/lib/module/index.js.map +1 -1
  48. package/lib/module/interfaces/augment-api-consts.js.map +1 -1
  49. package/lib/module/interfaces/augment-api-errors.js.map +1 -1
  50. package/lib/module/interfaces/augment-api-events.js.map +1 -1
  51. package/lib/module/interfaces/augment-api-query.js.map +1 -1
  52. package/lib/module/interfaces/augment-api-rpc.js.map +1 -1
  53. package/lib/module/interfaces/augment-api-runtime.js.map +1 -1
  54. package/lib/module/interfaces/augment-api-tx.js.map +1 -1
  55. package/lib/module/interfaces/augment-api.js.map +1 -1
  56. package/lib/module/interfaces/augment-types.js.map +1 -1
  57. package/lib/module/interfaces/definitions.js.map +1 -1
  58. package/lib/module/interfaces/defintions.js.map +1 -1
  59. package/lib/module/interfaces/fulaNativeModule.js.map +1 -1
  60. package/lib/module/interfaces/index.js.map +1 -1
  61. package/lib/module/interfaces/lookup.js +300 -300
  62. package/lib/module/interfaces/lookup.js.map +1 -1
  63. package/lib/module/interfaces/registry.js.map +1 -1
  64. package/lib/module/interfaces/types-lookup.js.map +1 -1
  65. package/lib/module/interfaces/types.js.map +1 -1
  66. package/lib/module/protocols/blockchain.js +66 -66
  67. package/lib/module/protocols/blockchain.js.map +1 -1
  68. package/lib/module/protocols/chain-api.js.map +1 -1
  69. package/lib/module/protocols/fula.js.map +1 -1
  70. package/lib/module/protocols/fx-ai.js +150 -0
  71. package/lib/module/protocols/fx-ai.js.map +1 -0
  72. package/lib/module/protocols/fxblox.js +3 -3
  73. package/lib/module/protocols/fxblox.js.map +1 -1
  74. package/lib/module/types/blockchain.js.map +1 -1
  75. package/lib/module/types/fxblox.js.map +1 -1
  76. package/package.json +176 -176
  77. package/react-native-fula.podspec +47 -47
  78. package/src/index.tsx +5 -4
  79. package/src/interfaces/augment-api-consts.ts +273 -273
  80. package/src/interfaces/augment-api-errors.ts +474 -474
  81. package/src/interfaces/augment-api-events.ts +448 -448
  82. package/src/interfaces/augment-api-query.ts +466 -466
  83. package/src/interfaces/augment-api-rpc.ts +617 -617
  84. package/src/interfaces/augment-api-runtime.ts +223 -223
  85. package/src/interfaces/augment-api-tx.ts +709 -709
  86. package/src/interfaces/augment-api.ts +9 -9
  87. package/src/interfaces/augment-types.ts +1322 -1322
  88. package/src/interfaces/definitions.ts +1 -1
  89. package/src/interfaces/defintions.ts +1 -1
  90. package/src/interfaces/fulaNativeModule.ts +175 -168
  91. package/src/interfaces/index.ts +3 -3
  92. package/src/interfaces/lookup.ts +2011 -2011
  93. package/src/interfaces/registry.ts +163 -163
  94. package/src/interfaces/types-lookup.ts +2165 -2165
  95. package/src/interfaces/types.ts +2 -2
  96. package/src/protocols/blockchain.ts +644 -644
  97. package/src/protocols/fx-ai.ts +182 -0
  98. package/src/protocols/fxblox.ts +443 -443
@@ -0,0 +1,182 @@
1
+ import Fula from '../interfaces/fulaNativeModule';
2
+ import { DeviceEventEmitter } from 'react-native';
3
+
4
+ export const chatWithAI = (
5
+ aiModel: string,
6
+ userMessage: string
7
+ ): Promise<string> => {
8
+ console.log('chatWithAI in react-native started');
9
+ let res = Fula.chatWithAI(aiModel, userMessage)
10
+ .then((res1) => {
11
+ try {
12
+ return res1; // Return the stream ID directly
13
+ } catch (e) {
14
+ console.error('Error parsing res in chatWithAI:', e);
15
+ throw e; // Rethrow the error to maintain the rejection state
16
+ }
17
+ })
18
+ .catch((err) => {
19
+ console.error('Error starting chat with AI:', err);
20
+ throw err; // Rethrow the error to maintain the rejection state
21
+ });
22
+ return res;
23
+ };
24
+
25
+ export const getChatChunk = (streamID: string): Promise<string> => {
26
+ console.log('getChatChunk in react-native started');
27
+ let res = Fula.getChatChunk(streamID)
28
+ .then((res1) => {
29
+ try {
30
+ if (!res1 || res1.trim() === "") {
31
+ console.log('Empty chunk received.');
32
+ return ""; // Return an empty string for empty chunks
33
+ }
34
+
35
+ console.log('Raw response from GetChatChunk:', res1); // Log raw response
36
+
37
+ const parsedChunk = JSON.parse(res1);
38
+ if (parsedChunk && parsedChunk.status && parsedChunk.msg) {
39
+ const content = parsedChunk.msg;
40
+ console.log('Processed content:', content); // Log processed content
41
+ return content;
42
+ }
43
+
44
+ return "";
45
+ } catch (e) {
46
+ console.error('Error parsing res in getChatChunk:', e);
47
+ throw e;
48
+ }
49
+ })
50
+ .catch((err) => {
51
+ console.error('Error getting chat chunk:', err);
52
+ throw err;
53
+ });
54
+ return res;
55
+ };
56
+
57
+ export const fetchChunksUsingIterator = (streamID: string): Promise<string> => {
58
+ return new Promise((resolve, reject) => {
59
+ let fullResponse = '';
60
+ let active = true;
61
+
62
+ const cleanup = () => {
63
+ active = false;
64
+ DeviceEventEmitter.removeAllListeners('onChunkReceived');
65
+ DeviceEventEmitter.removeAllListeners('onStreamingCompleted');
66
+ DeviceEventEmitter.removeAllListeners('onStreamError');
67
+ };
68
+
69
+ const chunkHandler = (chunk: string) => {
70
+ if (active) fullResponse += chunk;
71
+ console.log('Chunk received:', chunk);
72
+ };
73
+
74
+ const completionHandler = () => {
75
+ if (active) {
76
+ cleanup();
77
+ resolve(fullResponse);
78
+ }
79
+ };
80
+
81
+ const errorHandler = (error: string) => {
82
+ if (active) {
83
+ cleanup();
84
+ if (error.includes('EOF')) {
85
+ // Treat EOF as successful completion
86
+ console.log('Stream completed with EOF');
87
+ resolve(fullResponse);
88
+ } else {
89
+ console.error('Stream error:', error);
90
+ reject(new Error(error || 'Unknown stream error'));
91
+ }
92
+ }
93
+ };
94
+
95
+ DeviceEventEmitter.addListener('onChunkReceived', chunkHandler);
96
+ DeviceEventEmitter.addListener('onStreamingCompleted', completionHandler);
97
+ DeviceEventEmitter.addListener('onStreamError', errorHandler);
98
+
99
+ Fula.streamChunks(streamID)
100
+ .catch(error => {
101
+ if (active) {
102
+ cleanup();
103
+ if (error.message.includes('EOF')) {
104
+ resolve(fullResponse);
105
+ } else {
106
+ reject(error);
107
+ }
108
+ }
109
+ });
110
+ });
111
+ };
112
+
113
+ export interface StreamCallbacks {
114
+ onChunk?: (chunk: string) => void;
115
+ onComplete?: () => void;
116
+ onError?: (error: Error) => void;
117
+ }
118
+
119
+ export const streamChunks = (streamID: string, callbacks: StreamCallbacks): () => void => {
120
+ let active = true;
121
+
122
+ const cleanup = () => {
123
+ active = false;
124
+ DeviceEventEmitter.removeAllListeners('onChunkReceived');
125
+ DeviceEventEmitter.removeAllListeners('onStreamingCompleted');
126
+ DeviceEventEmitter.removeAllListeners('onStreamError');
127
+ };
128
+
129
+ const chunkHandler = (chunk: string) => {
130
+ if (active && callbacks.onChunk) {
131
+ callbacks.onChunk(chunk);
132
+ }
133
+ };
134
+
135
+ const completionHandler = () => {
136
+ if (active) {
137
+ cleanup();
138
+ if (callbacks.onComplete) {
139
+ callbacks.onComplete();
140
+ }
141
+ }
142
+ };
143
+
144
+ const errorHandler = (error: string) => {
145
+ if (active) {
146
+ cleanup();
147
+ if (error.includes('EOF')) {
148
+ // Treat EOF as successful completion
149
+ console.log('Stream completed with EOF');
150
+ if (callbacks.onComplete) {
151
+ callbacks.onComplete();
152
+ }
153
+ } else {
154
+ console.error('Stream error:', error);
155
+ if (callbacks.onError) {
156
+ callbacks.onError(new Error(error || 'Unknown stream error'));
157
+ }
158
+ }
159
+ }
160
+ };
161
+
162
+ DeviceEventEmitter.addListener('onChunkReceived', chunkHandler);
163
+ DeviceEventEmitter.addListener('onStreamingCompleted', completionHandler);
164
+ DeviceEventEmitter.addListener('onStreamError', errorHandler);
165
+
166
+ Fula.streamChunks(streamID)
167
+ .catch(error => {
168
+ if (active) {
169
+ cleanup();
170
+ if (error.message.includes('EOF')) {
171
+ if (callbacks.onComplete) {
172
+ callbacks.onComplete();
173
+ }
174
+ } else if (callbacks.onError) {
175
+ callbacks.onError(error);
176
+ }
177
+ }
178
+ });
179
+
180
+ // Return a cleanup function that the caller can use to stop listening
181
+ return cleanup;
182
+ };