srs-heritage-chatbot 1.0.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 (187) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +194 -0
  3. package/lib/commonjs/assets/chat-icon-mobile.svg +1 -0
  4. package/lib/commonjs/assets/heritage.png +0 -0
  5. package/lib/commonjs/assets/posiden.svg +51 -0
  6. package/lib/commonjs/components/LoadingTips.js +104 -0
  7. package/lib/commonjs/components/LoadingTips.js.map +1 -0
  8. package/lib/commonjs/components/email.js +461 -0
  9. package/lib/commonjs/components/email.js.map +1 -0
  10. package/lib/commonjs/components/feedback.js +114 -0
  11. package/lib/commonjs/components/feedback.js.map +1 -0
  12. package/lib/commonjs/components/header.js +126 -0
  13. package/lib/commonjs/components/header.js.map +1 -0
  14. package/lib/commonjs/components/input.js +144 -0
  15. package/lib/commonjs/components/input.js.map +1 -0
  16. package/lib/commonjs/components/productCard.js +688 -0
  17. package/lib/commonjs/components/productCard.js.map +1 -0
  18. package/lib/commonjs/components/progressCircle.js +99 -0
  19. package/lib/commonjs/components/progressCircle.js.map +1 -0
  20. package/lib/commonjs/components/testing.js +74 -0
  21. package/lib/commonjs/components/testing.js.map +1 -0
  22. package/lib/commonjs/components/voice.js +184 -0
  23. package/lib/commonjs/components/voice.js.map +1 -0
  24. package/lib/commonjs/components/welcomeButton.js +149 -0
  25. package/lib/commonjs/components/welcomeButton.js.map +1 -0
  26. package/lib/commonjs/components/welcomeInput.js +137 -0
  27. package/lib/commonjs/components/welcomeInput.js.map +1 -0
  28. package/lib/commonjs/contexts/AppContext.js +552 -0
  29. package/lib/commonjs/contexts/AppContext.js.map +1 -0
  30. package/lib/commonjs/hooks/Stream.js +599 -0
  31. package/lib/commonjs/hooks/Stream.js.map +1 -0
  32. package/lib/commonjs/hooks/useAsyncStorage.js +36 -0
  33. package/lib/commonjs/hooks/useAsyncStorage.js.map +1 -0
  34. package/lib/commonjs/index.js +44 -0
  35. package/lib/commonjs/index.js.map +1 -0
  36. package/lib/commonjs/layout/disclaimer.js +208 -0
  37. package/lib/commonjs/layout/disclaimer.js.map +1 -0
  38. package/lib/commonjs/layout/ex.js +254 -0
  39. package/lib/commonjs/layout/ex.js.map +1 -0
  40. package/lib/commonjs/layout/icon.js +118 -0
  41. package/lib/commonjs/layout/icon.js.map +1 -0
  42. package/lib/commonjs/layout/layout.js +168 -0
  43. package/lib/commonjs/layout/layout.js.map +1 -0
  44. package/lib/commonjs/layout/welcome.js +160 -0
  45. package/lib/commonjs/layout/welcome.js.map +1 -0
  46. package/lib/commonjs/layout/window.js +396 -0
  47. package/lib/commonjs/layout/window.js.map +1 -0
  48. package/lib/commonjs/utils/audioRecorder.js +412 -0
  49. package/lib/commonjs/utils/audioRecorder.js.map +1 -0
  50. package/lib/commonjs/utils/cloudinary.js +69 -0
  51. package/lib/commonjs/utils/cloudinary.js.map +1 -0
  52. package/lib/commonjs/utils/storage.js +76 -0
  53. package/lib/commonjs/utils/storage.js.map +1 -0
  54. package/lib/commonjs/utils/textToSpeech.js +53 -0
  55. package/lib/commonjs/utils/textToSpeech.js.map +1 -0
  56. package/lib/module/assets/chat-icon-mobile.svg +1 -0
  57. package/lib/module/assets/heritage.png +0 -0
  58. package/lib/module/assets/posiden.svg +51 -0
  59. package/lib/module/components/LoadingTips.js +95 -0
  60. package/lib/module/components/LoadingTips.js.map +1 -0
  61. package/lib/module/components/email.js +452 -0
  62. package/lib/module/components/email.js.map +1 -0
  63. package/lib/module/components/feedback.js +105 -0
  64. package/lib/module/components/feedback.js.map +1 -0
  65. package/lib/module/components/header.js +117 -0
  66. package/lib/module/components/header.js.map +1 -0
  67. package/lib/module/components/input.js +135 -0
  68. package/lib/module/components/input.js.map +1 -0
  69. package/lib/module/components/productCard.js +679 -0
  70. package/lib/module/components/productCard.js.map +1 -0
  71. package/lib/module/components/progressCircle.js +91 -0
  72. package/lib/module/components/progressCircle.js.map +1 -0
  73. package/lib/module/components/testing.js +66 -0
  74. package/lib/module/components/testing.js.map +1 -0
  75. package/lib/module/components/voice.js +175 -0
  76. package/lib/module/components/voice.js.map +1 -0
  77. package/lib/module/components/welcomeButton.js +140 -0
  78. package/lib/module/components/welcomeButton.js.map +1 -0
  79. package/lib/module/components/welcomeInput.js +128 -0
  80. package/lib/module/components/welcomeInput.js.map +1 -0
  81. package/lib/module/contexts/AppContext.js +542 -0
  82. package/lib/module/contexts/AppContext.js.map +1 -0
  83. package/lib/module/hooks/Stream.js +592 -0
  84. package/lib/module/hooks/Stream.js.map +1 -0
  85. package/lib/module/hooks/useAsyncStorage.js +29 -0
  86. package/lib/module/hooks/useAsyncStorage.js.map +1 -0
  87. package/lib/module/index.js +36 -0
  88. package/lib/module/index.js.map +1 -0
  89. package/lib/module/layout/disclaimer.js +199 -0
  90. package/lib/module/layout/disclaimer.js.map +1 -0
  91. package/lib/module/layout/ex.js +253 -0
  92. package/lib/module/layout/ex.js.map +1 -0
  93. package/lib/module/layout/icon.js +108 -0
  94. package/lib/module/layout/icon.js.map +1 -0
  95. package/lib/module/layout/layout.js +160 -0
  96. package/lib/module/layout/layout.js.map +1 -0
  97. package/lib/module/layout/welcome.js +150 -0
  98. package/lib/module/layout/welcome.js.map +1 -0
  99. package/lib/module/layout/window.js +387 -0
  100. package/lib/module/layout/window.js.map +1 -0
  101. package/lib/module/utils/audioRecorder.js +398 -0
  102. package/lib/module/utils/audioRecorder.js.map +1 -0
  103. package/lib/module/utils/cloudinary.js +61 -0
  104. package/lib/module/utils/cloudinary.js.map +1 -0
  105. package/lib/module/utils/storage.js +67 -0
  106. package/lib/module/utils/storage.js.map +1 -0
  107. package/lib/module/utils/textToSpeech.js +43 -0
  108. package/lib/module/utils/textToSpeech.js.map +1 -0
  109. package/lib/typescript/components/LoadingTips.d.ts +3 -0
  110. package/lib/typescript/components/LoadingTips.d.ts.map +1 -0
  111. package/lib/typescript/components/email.d.ts +6 -0
  112. package/lib/typescript/components/email.d.ts.map +1 -0
  113. package/lib/typescript/components/feedback.d.ts +6 -0
  114. package/lib/typescript/components/feedback.d.ts.map +1 -0
  115. package/lib/typescript/components/header.d.ts +3 -0
  116. package/lib/typescript/components/header.d.ts.map +1 -0
  117. package/lib/typescript/components/input.d.ts +6 -0
  118. package/lib/typescript/components/input.d.ts.map +1 -0
  119. package/lib/typescript/components/productCard.d.ts +7 -0
  120. package/lib/typescript/components/productCard.d.ts.map +1 -0
  121. package/lib/typescript/components/progressCircle.d.ts +3 -0
  122. package/lib/typescript/components/progressCircle.d.ts.map +1 -0
  123. package/lib/typescript/components/testing.d.ts +6 -0
  124. package/lib/typescript/components/testing.d.ts.map +1 -0
  125. package/lib/typescript/components/voice.d.ts +5 -0
  126. package/lib/typescript/components/voice.d.ts.map +1 -0
  127. package/lib/typescript/components/welcomeButton.d.ts +4 -0
  128. package/lib/typescript/components/welcomeButton.d.ts.map +1 -0
  129. package/lib/typescript/components/welcomeInput.d.ts +6 -0
  130. package/lib/typescript/components/welcomeInput.d.ts.map +1 -0
  131. package/lib/typescript/contexts/AppContext.d.ts +10 -0
  132. package/lib/typescript/contexts/AppContext.d.ts.map +1 -0
  133. package/lib/typescript/hooks/Stream.d.ts +2 -0
  134. package/lib/typescript/hooks/Stream.d.ts.map +1 -0
  135. package/lib/typescript/hooks/useAsyncStorage.d.ts +2 -0
  136. package/lib/typescript/hooks/useAsyncStorage.d.ts.map +1 -0
  137. package/lib/typescript/index.d.ts +8 -0
  138. package/lib/typescript/index.d.ts.map +1 -0
  139. package/lib/typescript/layout/disclaimer.d.ts +5 -0
  140. package/lib/typescript/layout/disclaimer.d.ts.map +1 -0
  141. package/lib/typescript/layout/ex.d.ts +1 -0
  142. package/lib/typescript/layout/ex.d.ts.map +1 -0
  143. package/lib/typescript/layout/icon.d.ts +3 -0
  144. package/lib/typescript/layout/icon.d.ts.map +1 -0
  145. package/lib/typescript/layout/layout.d.ts +3 -0
  146. package/lib/typescript/layout/layout.d.ts.map +1 -0
  147. package/lib/typescript/layout/welcome.d.ts +6 -0
  148. package/lib/typescript/layout/welcome.d.ts.map +1 -0
  149. package/lib/typescript/layout/window.d.ts +5 -0
  150. package/lib/typescript/layout/window.d.ts.map +1 -0
  151. package/lib/typescript/utils/audioRecorder.d.ts +9 -0
  152. package/lib/typescript/utils/audioRecorder.d.ts.map +1 -0
  153. package/lib/typescript/utils/cloudinary.d.ts +17 -0
  154. package/lib/typescript/utils/cloudinary.d.ts.map +1 -0
  155. package/lib/typescript/utils/storage.d.ts +29 -0
  156. package/lib/typescript/utils/storage.d.ts.map +1 -0
  157. package/lib/typescript/utils/textToSpeech.d.ts +2 -0
  158. package/lib/typescript/utils/textToSpeech.d.ts.map +1 -0
  159. package/package.json +109 -0
  160. package/src/assets/chat-icon-mobile.svg +1 -0
  161. package/src/assets/heritage.png +0 -0
  162. package/src/assets/posiden.svg +51 -0
  163. package/src/components/LoadingTips.js +99 -0
  164. package/src/components/email.js +467 -0
  165. package/src/components/feedback.js +114 -0
  166. package/src/components/header.js +119 -0
  167. package/src/components/input.js +133 -0
  168. package/src/components/productCard.js +815 -0
  169. package/src/components/progressCircle.js +88 -0
  170. package/src/components/testing.js +60 -0
  171. package/src/components/voice.js +228 -0
  172. package/src/components/welcomeButton.js +161 -0
  173. package/src/components/welcomeInput.js +133 -0
  174. package/src/contexts/AppContext.js +678 -0
  175. package/src/hooks/Stream.js +655 -0
  176. package/src/hooks/useAsyncStorage.js +33 -0
  177. package/src/index.js +30 -0
  178. package/src/layout/disclaimer.js +231 -0
  179. package/src/layout/ex.js +252 -0
  180. package/src/layout/icon.js +105 -0
  181. package/src/layout/layout.js +160 -0
  182. package/src/layout/welcome.js +172 -0
  183. package/src/layout/window.js +476 -0
  184. package/src/utils/audioRecorder.js +445 -0
  185. package/src/utils/cloudinary.js +61 -0
  186. package/src/utils/storage.ts +89 -0
  187. package/src/utils/textToSpeech.js +49 -0
@@ -0,0 +1,599 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useWebSocketMessage = useWebSocketMessage;
7
+ var _react = _interopRequireWildcard(require("react"));
8
+ var _AppContext = require("../contexts/AppContext");
9
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
10
+ function useWebSocketMessage() {
11
+ const {
12
+ setIsComplete,
13
+ startStreaming,
14
+ setMessages,
15
+ messages,
16
+ setGhostMessage,
17
+ data,
18
+ setTypingIndicator,
19
+ setStartStreaming,
20
+ lastUserMessage,
21
+ stopActivated,
22
+ sessionId,
23
+ setGhostCard,
24
+ BASE_URL,
25
+ setStopActivated,
26
+ setLastMessageId,
27
+ conversationStartTime
28
+ } = (0, _react.useContext)(_AppContext.AppContext);
29
+ const wsProtocol = 'wss://';
30
+ //const wsProtocol = 'ws://';
31
+ const wsUrl = BASE_URL.replace(/^http(s)?:\/\//, '');
32
+ const ENDPOINT = '/send/event';
33
+ const payload = {
34
+ customer_code: data.customer_code,
35
+ branch_code: data.branch_code,
36
+ // "NBPISLA"
37
+ branch_full_name: data.branch_full_name,
38
+ customer_token: data.customer_token,
39
+ active_ship_to_information: {
40
+ shipToId: data.active_ship_to
41
+ /* "customerId": 0,
42
+ "customerCode": "HPTA",
43
+ "shipToSequenceId": 1,
44
+ "customerShipToName": "HERITAGE PLUS TEST ACCOUNT",
45
+ "addressLine1": "7440 STATE HIGHWAY 121",
46
+ "addressLine2": "",
47
+ "addressLine3": "",
48
+ "city": "MCKINNEY",
49
+ "state": "TX",
50
+ "zipCode": "750702196",
51
+ "phone": "2144914149",
52
+ "fax": " ",
53
+ "orderAckEmail": "",
54
+ "customerPORequiredInd": "N",
55
+ "termsCode": "NET30",
56
+ "shipVia": "",
57
+ "salesPerson": "AS201585",
58
+ "salesPersonName": "",
59
+ "salesPersonCellPhone": "405-226-5844",
60
+ "salesPersonEmail": "Aaron.Spitz@heritagepsg.com",
61
+ "insideSalesPerson": "",
62
+ "secondarySalesPersonName": "",
63
+ "secondarySalesPersonEmail": null */
64
+ },
65
+ branch_details: data.branch_details,
66
+ /* branch_details: {
67
+ "active_branch_business_hours": "8:00 AM - 4:30 PM",
68
+ "active_branch_email": "OrdersHarrisburg@bel-aqua.com",
69
+ "active_branch_location": "Elizabethtown,PA",
70
+ "active_branch_name": "BEL-AQUA HARRISBURG",
71
+ "active_branch_phone": "(717)-689-3314",
72
+ "active_brand_name": "BEL-AQUA"
73
+ }, */
74
+ user_query: lastUserMessage,
75
+ session_id: data.session_id || data.session || sessionId,
76
+ conversation_start_time: conversationStartTime,
77
+ // /* customer_name: "Cristin Connerney",
78
+ user_UUID: data.user_id || 'mobile_user_unspecified',
79
+ device: 'mobile',
80
+ window_location: 'mobile'
81
+ };
82
+ const wsRef = (0, _react.useRef)(null);
83
+ (0, _react.useEffect)(() => {
84
+ if (startStreaming) {
85
+ console.log(payload, BASE_URL);
86
+ const socketUrl = `${wsProtocol}${wsUrl}${ENDPOINT}`;
87
+ console.log(socketUrl);
88
+ const ws = new WebSocket(socketUrl);
89
+ wsRef.current = ws;
90
+ ws.onopen = () => {
91
+ console.log('WebSocket connection established.');
92
+ ws.send(JSON.stringify(payload));
93
+ };
94
+ ws.onmessage = event => {
95
+ var _response$resource_de, _response$resource_de2;
96
+ const response = JSON.parse(event.data);
97
+ if (response.type !== 'chunk') {
98
+ console.log(JSON.stringify(response, null, 2));
99
+ }
100
+ switch (response.type) {
101
+ case 'middle_message':
102
+ const middleMessage = {
103
+ type: 'middle',
104
+ text: response.message,
105
+ products: [],
106
+ product_cards: 'False'
107
+ };
108
+ setMessages([...messages, middleMessage]);
109
+ break;
110
+ case 'message':
111
+ if (response.product_cards == 'False' || response.product_cards == false) {
112
+ setGhostMessage(false);
113
+ setTypingIndicator(false);
114
+ } else {
115
+ setGhostMessage(false);
116
+ setGhostCard(true);
117
+ }
118
+ const newMessage = {
119
+ type: 'ai',
120
+ message_id: response.message_id || '',
121
+ text: response.message,
122
+ feedback: 'True',
123
+ products: [],
124
+ product_cards: response.product_cards || 'False',
125
+ resource: (response === null || response === void 0 || (_response$resource_de = response.resource_details) === null || _response$resource_de === void 0 || (_response$resource_de = _response$resource_de[0]) === null || _response$resource_de === void 0 ? void 0 : _response$resource_de.link) ?? '',
126
+ resource_type: (response === null || response === void 0 || (_response$resource_de2 = response.resource_details) === null || _response$resource_de2 === void 0 || (_response$resource_de2 = _response$resource_de2[0]) === null || _response$resource_de2 === void 0 ? void 0 : _response$resource_de2.type) ?? ''
127
+ };
128
+ setMessages(prevMessages => [...prevMessages, newMessage]);
129
+ setLastMessageId(response.message_id);
130
+ break;
131
+ case 'chunk':
132
+ const newContent = response.chunk;
133
+ const newMessageId = response.message_id;
134
+ setMessages(prevMessages => {
135
+ if (prevMessages.length > 0 && prevMessages[prevMessages.length - 1].type === 'ai') {
136
+ return prevMessages.map((message, index) => index === prevMessages.length - 1 ? {
137
+ ...message,
138
+ text: message.text + newContent,
139
+ message_id: newMessageId || message.message_id,
140
+ feedback: 'True'
141
+ } : message);
142
+ } else {
143
+ return [...prevMessages, {
144
+ type: 'ai',
145
+ text: newContent,
146
+ message_id: newMessageId,
147
+ feedback: 'True'
148
+ }];
149
+ }
150
+ });
151
+ setGhostMessage(false);
152
+ if (newMessageId) {
153
+ setLastMessageId(newMessageId);
154
+ }
155
+ break;
156
+ case 'product_cards':
157
+ console.log('\n\n\n\nthis is for my own sanity: ', response.products[0], '\n\n\n\n');
158
+ setMessages(prevMessages => {
159
+ const lastMessageIndex = prevMessages.length - 1;
160
+ if (prevMessages[lastMessageIndex] && prevMessages[lastMessageIndex].type === 'ai') {
161
+ const expandedProducts = response.products.map(prod => ({
162
+ part_number: prod.part_number || '',
163
+ inventory_info: prod.inventory_info ? {
164
+ default_uom: prod.inventory_info.default_uom || '',
165
+ is_valid: prod.inventory_info.is_valid || false,
166
+ info_by_uom: prod.inventory_info.info_by_uom ? Object.keys(prod.inventory_info.info_by_uom).reduce((acc, key) => {
167
+ const value = prod.inventory_info.info_by_uom[key] || {};
168
+ acc[key] = {
169
+ gross_price: value.gross_price ?? 0,
170
+ net_price: value.net_price ?? 0,
171
+ is_on_sale: value.is_on_sale ?? false,
172
+ quantity_available: value.quantity_available ?? 0,
173
+ discounts: value.discounts ?? null,
174
+ min_pack_qty: value.min_pack_qty ?? 0
175
+ };
176
+ return acc;
177
+ }, {}) : {}
178
+ } : {},
179
+ product_details: prod.product_details ? {
180
+ brand: prod.product_details.brand || '',
181
+ flow: prod.product_details.flow || '',
182
+ heritage_link: prod.product_details.heritage_link || '',
183
+ image_url: prod.product_details.image_url || '',
184
+ is_pump: prod.product_details.is_pump || '',
185
+ manufacturer_id: prod.product_details.manufacturer_id || '',
186
+ mfg_number: prod.product_details.mfg_number || '',
187
+ part_number: prod.product_details.part_number || '',
188
+ product_description: prod.product_details.product_description || '',
189
+ product_name: prod.product_details.product_name || '',
190
+ type: prod.product_details.type || '',
191
+ vertical: prod.product_details.vertical || '',
192
+ sku: prod.product_details.sku || ''
193
+ } : {}
194
+ }));
195
+ const updatedLastMessage = {
196
+ ...prevMessages[lastMessageIndex],
197
+ products: expandedProducts,
198
+ product_cards: 'True'
199
+ };
200
+ return [...prevMessages.slice(0, lastMessageIndex), updatedLastMessage];
201
+ }
202
+ return prevMessages;
203
+ });
204
+ setGhostMessage(false);
205
+ setTypingIndicator(false);
206
+ setGhostCard(false);
207
+ break;
208
+ case 'product_document':
209
+ setMessages(prevMessages => {
210
+ const lastMessageIndex = prevMessages.length - 1;
211
+ if (prevMessages[lastMessageIndex] && prevMessages[lastMessageIndex].type === 'ai') {
212
+ var _response$resource_de3, _response$resource_de4;
213
+ const updatedLastMessage = {
214
+ ...prevMessages[lastMessageIndex],
215
+ resource: (response === null || response === void 0 || (_response$resource_de3 = response.resource_details) === null || _response$resource_de3 === void 0 || (_response$resource_de3 = _response$resource_de3[0]) === null || _response$resource_de3 === void 0 ? void 0 : _response$resource_de3.link) ?? '',
216
+ resource_type: (response === null || response === void 0 || (_response$resource_de4 = response.resource_details) === null || _response$resource_de4 === void 0 || (_response$resource_de4 = _response$resource_de4[0]) === null || _response$resource_de4 === void 0 ? void 0 : _response$resource_de4.type) ?? ''
217
+ };
218
+ return [...prevMessages.slice(0, lastMessageIndex), updatedLastMessage];
219
+ }
220
+ });
221
+ setGhostMessage(false);
222
+ setTypingIndicator(false);
223
+ setGhostCard(false);
224
+ break;
225
+ case 'suggested_questions':
226
+ setMessages(prevMessages => {
227
+ const lastMessageIndex = prevMessages.length - 1;
228
+ if (prevMessages[lastMessageIndex] && prevMessages[lastMessageIndex].type === 'ai') {
229
+ const updatedLastMessage = {
230
+ ...prevMessages[lastMessageIndex],
231
+ suggested_questions: true,
232
+ questions: response.suggested_questions
233
+ };
234
+ return [...prevMessages.slice(0, lastMessageIndex), updatedLastMessage];
235
+ }
236
+ });
237
+ break;
238
+ case 'setComplete':
239
+ setTypingIndicator(false);
240
+ setStartStreaming(false);
241
+ setGhostCard(false);
242
+ break;
243
+ }
244
+ };
245
+ ws.onerror = error => {
246
+ setStartStreaming(false);
247
+ setGhostMessage(false);
248
+ setTypingIndicator(false);
249
+ setGhostCard(false);
250
+ };
251
+ ws.onclose = event => {
252
+ console.log('WebSocket connection closed:', event.reason);
253
+ setStartStreaming(false);
254
+ setGhostMessage(false);
255
+ setTypingIndicator(false);
256
+ setGhostCard(false);
257
+ };
258
+ return () => {
259
+ ws.close();
260
+ };
261
+ }
262
+ }, [startStreaming]);
263
+ (0, _react.useEffect)(() => {
264
+ if (wsRef.current && wsRef.current.readyState === WebSocket.OPEN) {
265
+ wsRef.current.close();
266
+ setStartStreaming(false);
267
+ setGhostMessage(false);
268
+ setGhostCard(false);
269
+ setTypingIndicator(false);
270
+ setStopActivated(false);
271
+ }
272
+ }, [stopActivated, setStartStreaming]);
273
+ }
274
+
275
+ // import React, { useState, useEffect, useRef, useContext } from 'react';
276
+ // import { AppContext } from '../contexts/AppContext';
277
+ //
278
+ // export function useWebSocketMessage() {
279
+ // const {
280
+ // setIsComplete,
281
+ // startStreaming,
282
+ // setMessages,
283
+ // messages,
284
+ // setGhostMessage,
285
+ // data,
286
+ // setTypingIndicator,
287
+ // setStartStreaming,
288
+ // lastUserMessage,
289
+ // stopActivated,
290
+ // sessionId,
291
+ // setGhostCard,
292
+ // BASE_URL,
293
+ // setStopActivated,
294
+ // setLastMessageId,
295
+ // conversationStartTime,
296
+ // } = useContext(AppContext);
297
+ //
298
+ // const wsProtocol = 'wss://';
299
+ // const wsUrl = BASE_URL.replace(/^http(s)?:\/\//, '');
300
+ // const ENDPOINT = '/send/event';
301
+ //
302
+ // const payload = {
303
+ // customer_code: data.customer_code,
304
+ // branch_code: data.branch_code,
305
+ // branch_full_name: data.branch_full_name,
306
+ // customer_token: data.customer_token,
307
+ // active_ship_to_information: {
308
+ // shipToId: data.active_ship_to,
309
+ // },
310
+ // branch_details: data.branch_details,
311
+ // user_query: lastUserMessage,
312
+ // session_id: data.session_id || data.session || sessionId,
313
+ // conversation_start_time: conversationStartTime,
314
+ // user_UUID: data.user_id || 'mobile_user_unspecified',
315
+ // device: 'mobile',
316
+ // window_location: 'mobile',
317
+ // };
318
+ //
319
+ // const wsRef = useRef(null);
320
+ //
321
+ // useEffect(() => {
322
+ // if (startStreaming) {
323
+ // console.log(payload, BASE_URL);
324
+ // const socketUrl = `${wsProtocol}${wsUrl}${ENDPOINT}`;
325
+ // console.log(socketUrl);
326
+ //
327
+ // const ws = new WebSocket(socketUrl);
328
+ // wsRef.current = ws;
329
+ //
330
+ // ws.onopen = () => {
331
+ // console.log('WebSocket connection established.');
332
+ // ws.send(JSON.stringify(payload));
333
+ // };
334
+ //
335
+ // ws.onmessage = event => {
336
+ // const response = JSON.parse(event.data);
337
+ //
338
+ // if (response.type !== 'chunk') {
339
+ // console.log(JSON.stringify(response, null, 2));
340
+ // }
341
+ // switch (response.type) {
342
+ // case 'middle_message':
343
+ // const middleMessage = {
344
+ // type: 'middle',
345
+ // text: response.message,
346
+ // products: [],
347
+ // product_cards: 'False',
348
+ // };
349
+ // setMessages(prevMessages => [...prevMessages, middleMessage]);
350
+ // break;
351
+ // case 'message':
352
+ // if (
353
+ // response.product_cards == 'False' ||
354
+ // response.product_cards == false
355
+ // ) {
356
+ // setGhostMessage(false);
357
+ // setTypingIndicator(false);
358
+ // } else {
359
+ // setGhostMessage(false);
360
+ // setGhostCard(true);
361
+ // }
362
+ // const newMessage = {
363
+ // type: 'ai',
364
+ // message_id: response.message_id || '',
365
+ // text: response.message,
366
+ // feedback: 'True',
367
+ // products: [],
368
+ // product_cards: response.product_cards || 'False',
369
+ // resource: response?.resource_details?.[0]?.link ?? '',
370
+ // resource_type: response?.resource_details?.[0]?.type ?? '',
371
+ // };
372
+ // setMessages(prevMessages => [...prevMessages, newMessage]);
373
+ // setLastMessageId(response.message_id);
374
+ // break;
375
+ // case 'chunk':
376
+ // const newContent = response.chunk;
377
+ // const newMessageId = response.message_id;
378
+ //
379
+ // setMessages(prevMessages => {
380
+ // if (
381
+ // prevMessages.length > 0 &&
382
+ // prevMessages[prevMessages.length - 1].type === 'ai'
383
+ // ) {
384
+ // return prevMessages.map((message, index) =>
385
+ // index === prevMessages.length - 1
386
+ // ? {
387
+ // ...message,
388
+ // text: message.text + newContent,
389
+ // message_id: newMessageId || message.message_id,
390
+ // feedback: 'True',
391
+ // }
392
+ // : message,
393
+ // );
394
+ // } else {
395
+ // return [
396
+ // ...prevMessages,
397
+ // {
398
+ // type: 'ai',
399
+ // text: newContent,
400
+ // message_id: newMessageId,
401
+ // feedback: 'True',
402
+ // },
403
+ // ];
404
+ // }
405
+ // });
406
+ // setGhostMessage(false);
407
+ // if (newMessageId) {
408
+ // setLastMessageId(newMessageId);
409
+ // }
410
+ // break;
411
+ // case 'product_cards':
412
+ // console.log('🛒 PRODUCT_CARDS RECEIVED:', response);
413
+ // setMessages(prevMessages => {
414
+ // console.log(
415
+ // '📦 Current messages array length:',
416
+ // prevMessages.length,
417
+ // );
418
+ // const lastMessageIndex = prevMessages.length - 1;
419
+ //
420
+ // if (lastMessageIndex < 0) {
421
+ // console.warn('⚠️ No messages exist yet!');
422
+ // return prevMessages;
423
+ // }
424
+ //
425
+ // const lastMessage = prevMessages[lastMessageIndex];
426
+ // console.log('📝 Last message:', {
427
+ // type: lastMessage?.type,
428
+ // message_id: lastMessage?.message_id,
429
+ // has_products: !!lastMessage?.products,
430
+ // text_preview: lastMessage?.text?.substring(0, 50),
431
+ // });
432
+ //
433
+ // if (lastMessage && lastMessage.type === 'ai') {
434
+ // const expandedProducts = response.products.map(prod => ({
435
+ // part_number: prod.part_number || '',
436
+ // inventory_info: prod.inventory_info
437
+ // ? {
438
+ // default_uom: prod.inventory_info.default_uom || '',
439
+ // is_valid: prod.inventory_info.is_valid || false,
440
+ // info_by_uom: prod.inventory_info.info_by_uom
441
+ // ? Object.keys(prod.inventory_info.info_by_uom).reduce(
442
+ // (acc, key) => {
443
+ // const value =
444
+ // prod.inventory_info.info_by_uom[key] || {};
445
+ // acc[key] = {
446
+ // gross_price: value.gross_price ?? 0,
447
+ // net_price: value.net_price ?? 0,
448
+ // is_on_sale: value.is_on_sale ?? false,
449
+ // quantity_available:
450
+ // value.quantity_available ?? 0,
451
+ // discounts: value.discounts ?? null,
452
+ // min_pack_qty: value.min_pack_qty ?? 0,
453
+ // };
454
+ // return acc;
455
+ // },
456
+ // {},
457
+ // )
458
+ // : {},
459
+ // }
460
+ // : {},
461
+ // product_details: prod.product_details
462
+ // ? {
463
+ // brand: prod.product_details.brand || '',
464
+ // flow: prod.product_details.flow || '',
465
+ // heritage_link: prod.product_details.heritage_link || '',
466
+ // image_url: prod.product_details.image_url || '',
467
+ // is_pump: prod.product_details.is_pump || '',
468
+ // manufacturer_id:
469
+ // prod.product_details.manufacturer_id || '',
470
+ // mfg_number: prod.product_details.mfg_number || '',
471
+ // part_number: prod.product_details.part_number || '',
472
+ // product_description:
473
+ // prod.product_details.product_description || '',
474
+ // product_name: prod.product_details.product_name || '',
475
+ // type: prod.product_details.type || '',
476
+ // vertical: prod.product_details.vertical || '',
477
+ // sku: prod.product_details.sku || '',
478
+ // }
479
+ // : {},
480
+ // }));
481
+ //
482
+ // console.log(
483
+ // '✅ Merging',
484
+ // expandedProducts.length,
485
+ // 'products into last message',
486
+ // );
487
+ //
488
+ // const updatedLastMessage = {
489
+ // ...lastMessage,
490
+ // products: expandedProducts,
491
+ // product_cards: 'True',
492
+ // };
493
+ //
494
+ // const newMessages = [
495
+ // ...prevMessages.slice(0, lastMessageIndex),
496
+ // updatedLastMessage,
497
+ // ];
498
+ //
499
+ // console.log(
500
+ // '🎯 Updated message now has products:',
501
+ // updatedLastMessage.products.length,
502
+ // );
503
+ // return newMessages;
504
+ // }
505
+ //
506
+ // console.warn("⚠️ Last message is not AI type or doesn't exist");
507
+ // return prevMessages;
508
+ // });
509
+ //
510
+ // setGhostMessage(false);
511
+ // setTypingIndicator(false);
512
+ // setGhostCard(false);
513
+ // break;
514
+ // case 'product_document':
515
+ // setMessages(prevMessages => {
516
+ // const lastMessageIndex = prevMessages.length - 1;
517
+ // if (
518
+ // prevMessages[lastMessageIndex] &&
519
+ // prevMessages[lastMessageIndex].type === 'ai'
520
+ // ) {
521
+ // const updatedLastMessage = {
522
+ // ...prevMessages[lastMessageIndex],
523
+ // resource: response?.resource_details?.[0]?.link ?? '',
524
+ // resource_type: response?.resource_details?.[0]?.type ?? '',
525
+ // };
526
+ // return [
527
+ // ...prevMessages.slice(0, lastMessageIndex),
528
+ // updatedLastMessage,
529
+ // ];
530
+ // }
531
+ // // FIX: Always return prevMessages if condition not met
532
+ // return prevMessages;
533
+ // });
534
+ // setGhostMessage(false);
535
+ // setTypingIndicator(false);
536
+ // setGhostCard(false);
537
+ // break;
538
+ // case 'suggested_questions':
539
+ // setMessages(prevMessages => {
540
+ // const lastMessageIndex = prevMessages.length - 1;
541
+ // if (
542
+ // prevMessages[lastMessageIndex] &&
543
+ // prevMessages[lastMessageIndex].type === 'ai'
544
+ // ) {
545
+ // const updatedLastMessage = {
546
+ // ...prevMessages[lastMessageIndex],
547
+ // suggested_questions: true,
548
+ // questions: response.suggested_questions,
549
+ // };
550
+ // return [
551
+ // ...prevMessages.slice(0, lastMessageIndex),
552
+ // updatedLastMessage,
553
+ // ];
554
+ // }
555
+ // // FIX: Always return prevMessages if condition not met
556
+ // return prevMessages;
557
+ // });
558
+ // break;
559
+ // case 'setComplete':
560
+ // setTypingIndicator(false);
561
+ // setStartStreaming(false);
562
+ // setGhostCard(false);
563
+ // break;
564
+ // }
565
+ // };
566
+ //
567
+ // ws.onerror = error => {
568
+ // setStartStreaming(false);
569
+ // setGhostMessage(false);
570
+ // setTypingIndicator(false);
571
+ // setGhostCard(false);
572
+ // };
573
+ //
574
+ // ws.onclose = event => {
575
+ // console.log('WebSocket connection closed:', event.reason);
576
+ // setStartStreaming(false);
577
+ // setGhostMessage(false);
578
+ // setTypingIndicator(false);
579
+ // setGhostCard(false);
580
+ // };
581
+ //
582
+ // return () => {
583
+ // ws.close();
584
+ // };
585
+ // }
586
+ // }, [startStreaming]);
587
+ //
588
+ // useEffect(() => {
589
+ // if (wsRef.current && wsRef.current.readyState === WebSocket.OPEN) {
590
+ // wsRef.current.close();
591
+ // setStartStreaming(false);
592
+ // setGhostMessage(false);
593
+ // setGhostCard(false);
594
+ // setTypingIndicator(false);
595
+ // setStopActivated(false);
596
+ // }
597
+ // }, [stopActivated, setStartStreaming]);
598
+ // }
599
+ //# sourceMappingURL=Stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","_interopRequireWildcard","require","_AppContext","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","useWebSocketMessage","setIsComplete","startStreaming","setMessages","messages","setGhostMessage","data","setTypingIndicator","setStartStreaming","lastUserMessage","stopActivated","sessionId","setGhostCard","BASE_URL","setStopActivated","setLastMessageId","conversationStartTime","useContext","AppContext","wsProtocol","wsUrl","replace","ENDPOINT","payload","customer_code","branch_code","branch_full_name","customer_token","active_ship_to_information","shipToId","active_ship_to","branch_details","user_query","session_id","session","conversation_start_time","user_UUID","user_id","device","window_location","wsRef","useRef","useEffect","console","log","socketUrl","ws","WebSocket","current","onopen","send","JSON","stringify","onmessage","event","_response$resource_de","_response$resource_de2","response","parse","type","middleMessage","text","message","products","product_cards","newMessage","message_id","feedback","resource","resource_details","link","resource_type","prevMessages","newContent","chunk","newMessageId","length","map","index","lastMessageIndex","expandedProducts","prod","part_number","inventory_info","default_uom","is_valid","info_by_uom","keys","reduce","acc","key","value","gross_price","net_price","is_on_sale","quantity_available","discounts","min_pack_qty","product_details","brand","flow","heritage_link","image_url","is_pump","manufacturer_id","mfg_number","product_description","product_name","vertical","sku","updatedLastMessage","slice","_response$resource_de3","_response$resource_de4","suggested_questions","questions","onerror","error","onclose","reason","close","readyState","OPEN"],"sourceRoot":"../../../src","sources":["hooks/Stream.js"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AAAoD,SAAAD,wBAAAG,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAL,uBAAA,YAAAA,CAAAG,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,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IF,KAAK,CAACQ,OAAO,IAAIR,KAAK,CAACQ,OAAO,CAACyE,UAAU,KAAK1E,SAAS,CAAC2E,IAAI,EAAE;MAChElF,KAAK,CAACQ,OAAO,CAACwE,KAAK,CAAC,CAAC;MACrBhH,iBAAiB,CAAC,KAAK,CAAC;MACxBH,eAAe,CAAC,KAAK,CAAC;MACtBO,YAAY,CAAC,KAAK,CAAC;MACnBL,kBAAkB,CAAC,KAAK,CAAC;MACzBO,gBAAgB,CAAC,KAAK,CAAC;IACzB;EACF,CAAC,EAAE,CAACJ,aAAa,EAAEF,iBAAiB,CAAC,CAAC;AACxC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = useAsyncStorage;
7
+ var _react = require("react");
8
+ var _asyncStorage = _interopRequireDefault(require("@react-native-async-storage/async-storage"));
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
+ function useAsyncStorage(key, defaultValue) {
11
+ const [value, setValue] = (0, _react.useState)(defaultValue);
12
+ (0, _react.useEffect)(() => {
13
+ const loadValue = async () => {
14
+ try {
15
+ const storedValue = await _asyncStorage.default.getItem(key);
16
+ if (storedValue !== null) {
17
+ setValue(JSON.parse(storedValue));
18
+ }
19
+ } catch (error) {
20
+ console.error(`Error loading data for key "${key}":`, error);
21
+ }
22
+ };
23
+ loadValue();
24
+ }, [key]);
25
+ const setValueInAsyncStorage = async newValue => {
26
+ try {
27
+ const result = typeof newValue === 'function' ? newValue(value) : newValue;
28
+ setValue(result);
29
+ await _asyncStorage.default.setItem(key, JSON.stringify(result));
30
+ } catch (error) {
31
+ console.error(`Error saving data for key "${key}":`, error);
32
+ }
33
+ };
34
+ return [value, setValueInAsyncStorage];
35
+ }
36
+ //# sourceMappingURL=useAsyncStorage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","require","_asyncStorage","_interopRequireDefault","e","__esModule","default","useAsyncStorage","key","defaultValue","value","setValue","useState","useEffect","loadValue","storedValue","AsyncStorage","getItem","JSON","parse","error","console","setValueInAsyncStorage","newValue","result","setItem","stringify"],"sourceRoot":"../../../src","sources":["hooks/useAsyncStorage.js"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,aAAA,GAAAC,sBAAA,CAAAF,OAAA;AAAqE,SAAAE,uBAAAC,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAEtD,SAASG,eAAeA,CAACC,GAAG,EAAEC,YAAY,EAAE;EACzD,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAG,IAAAC,eAAQ,EAACH,YAAY,CAAC;EAEhD,IAAAI,gBAAS,EAAC,MAAM;IACd,MAAMC,SAAS,GAAG,MAAAA,CAAA,KAAY;MAC5B,IAAI;QACF,MAAMC,WAAW,GAAG,MAAMC,qBAAY,CAACC,OAAO,CAACT,GAAG,CAAC;QACnD,IAAIO,WAAW,KAAK,IAAI,EAAE;UACxBJ,QAAQ,CAACO,IAAI,CAACC,KAAK,CAACJ,WAAW,CAAC,CAAC;QACnC;MACF,CAAC,CAAC,OAAOK,KAAK,EAAE;QACdC,OAAO,CAACD,KAAK,CAAC,+BAA+BZ,GAAG,IAAI,EAAEY,KAAK,CAAC;MAC9D;IACF,CAAC;IAEDN,SAAS,CAAC,CAAC;EACb,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