react-native-srschat 0.1.83 → 0.1.85

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 (59) hide show
  1. package/lib/commonjs/components/email.js +5 -9
  2. package/lib/commonjs/components/email.js.map +1 -1
  3. package/lib/commonjs/components/productCard.js +91 -86
  4. package/lib/commonjs/components/productCard.js.map +1 -1
  5. package/lib/commonjs/components/welcomeButton.js +4 -4
  6. package/lib/commonjs/components/welcomeButton.js.map +1 -1
  7. package/lib/commonjs/contexts/AppContext.js +46 -45
  8. package/lib/commonjs/contexts/AppContext.js.map +1 -1
  9. package/lib/commonjs/hooks/Stream.js +399 -74
  10. package/lib/commonjs/hooks/Stream.js.map +1 -1
  11. package/lib/commonjs/layout/disclaimer.js +36 -32
  12. package/lib/commonjs/layout/disclaimer.js.map +1 -1
  13. package/lib/commonjs/layout/welcome.js +8 -7
  14. package/lib/commonjs/layout/welcome.js.map +1 -1
  15. package/lib/commonjs/layout/window.js +152 -131
  16. package/lib/commonjs/layout/window.js.map +1 -1
  17. package/lib/commonjs/utils/audioRecorder.js.map +1 -1
  18. package/lib/commonjs/utils/storage.js +1 -1
  19. package/lib/module/components/email.js +5 -9
  20. package/lib/module/components/email.js.map +1 -1
  21. package/lib/module/components/productCard.js +94 -89
  22. package/lib/module/components/productCard.js.map +1 -1
  23. package/lib/module/components/welcomeButton.js +4 -4
  24. package/lib/module/components/welcomeButton.js.map +1 -1
  25. package/lib/module/contexts/AppContext.js +47 -46
  26. package/lib/module/contexts/AppContext.js.map +1 -1
  27. package/lib/module/hooks/Stream.js +400 -75
  28. package/lib/module/hooks/Stream.js.map +1 -1
  29. package/lib/module/layout/disclaimer.js +41 -37
  30. package/lib/module/layout/disclaimer.js.map +1 -1
  31. package/lib/module/layout/welcome.js +8 -7
  32. package/lib/module/layout/welcome.js.map +1 -1
  33. package/lib/module/layout/window.js +152 -131
  34. package/lib/module/layout/window.js.map +1 -1
  35. package/lib/module/utils/audioRecorder.js.map +1 -1
  36. package/lib/module/utils/storage.js +1 -1
  37. package/lib/typescript/components/email.d.ts.map +1 -1
  38. package/lib/typescript/components/productCard.d.ts +1 -1
  39. package/lib/typescript/components/productCard.d.ts.map +1 -1
  40. package/lib/typescript/components/welcomeButton.d.ts.map +1 -1
  41. package/lib/typescript/contexts/AppContext.d.ts +2 -2
  42. package/lib/typescript/contexts/AppContext.d.ts.map +1 -1
  43. package/lib/typescript/hooks/Stream.d.ts.map +1 -1
  44. package/lib/typescript/layout/disclaimer.d.ts +1 -1
  45. package/lib/typescript/layout/disclaimer.d.ts.map +1 -1
  46. package/lib/typescript/layout/welcome.d.ts.map +1 -1
  47. package/lib/typescript/layout/window.d.ts.map +1 -1
  48. package/lib/typescript/utils/audioRecorder.d.ts.map +1 -1
  49. package/package.json +2 -1
  50. package/src/components/email.js +4 -16
  51. package/src/components/productCard.js +279 -203
  52. package/src/components/welcomeButton.js +10 -10
  53. package/src/contexts/AppContext.js +185 -106
  54. package/src/hooks/Stream.js +607 -237
  55. package/src/layout/disclaimer.js +125 -78
  56. package/src/layout/welcome.js +58 -20
  57. package/src/layout/window.js +279 -140
  58. package/src/utils/audioRecorder.js +40 -34
  59. package/src/utils/storage.ts +2 -2
@@ -30,53 +30,53 @@ function useWebSocketMessage() {
30
30
  const wsUrl = BASE_URL.replace(/^http(s)?:\/\//, '');
31
31
  const ENDPOINT = '/send/event';
32
32
  const payload = {
33
- "customer_code": data.customer_code,
34
- "branch_code": data.branch_code,
35
- // "NBPISLA"
36
- "branch_full_name": data.branch_full_name,
37
- "customer_token": data.customer_token,
33
+ customer_code: data.customer_code,
34
+ branch_code: data.branch_code,
35
+ // "NBPISLA"
36
+ branch_full_name: data.branch_full_name,
37
+ customer_token: data.customer_token,
38
38
  active_ship_to_information: {
39
39
  shipToId: data.active_ship_to
40
40
  /* "customerId": 0,
41
- "customerCode": "HPTA",
42
- "shipToSequenceId": 1,
43
- "customerShipToName": "HERITAGE PLUS TEST ACCOUNT",
44
- "addressLine1": "7440 STATE HIGHWAY 121",
45
- "addressLine2": "",
46
- "addressLine3": "",
47
- "city": "MCKINNEY",
48
- "state": "TX",
49
- "zipCode": "750702196",
50
- "phone": "2144914149",
51
- "fax": " ",
52
- "orderAckEmail": "",
53
- "customerPORequiredInd": "N",
54
- "termsCode": "NET30",
55
- "shipVia": "",
56
- "salesPerson": "AS201585",
57
- "salesPersonName": "",
58
- "salesPersonCellPhone": "405-226-5844",
59
- "salesPersonEmail": "Aaron.Spitz@heritagepsg.com",
60
- "insideSalesPerson": "",
61
- "secondarySalesPersonName": "",
62
- "secondarySalesPersonEmail": null */
41
+ "customerCode": "HPTA",
42
+ "shipToSequenceId": 1,
43
+ "customerShipToName": "HERITAGE PLUS TEST ACCOUNT",
44
+ "addressLine1": "7440 STATE HIGHWAY 121",
45
+ "addressLine2": "",
46
+ "addressLine3": "",
47
+ "city": "MCKINNEY",
48
+ "state": "TX",
49
+ "zipCode": "750702196",
50
+ "phone": "2144914149",
51
+ "fax": " ",
52
+ "orderAckEmail": "",
53
+ "customerPORequiredInd": "N",
54
+ "termsCode": "NET30",
55
+ "shipVia": "",
56
+ "salesPerson": "AS201585",
57
+ "salesPersonName": "",
58
+ "salesPersonCellPhone": "405-226-5844",
59
+ "salesPersonEmail": "Aaron.Spitz@heritagepsg.com",
60
+ "insideSalesPerson": "",
61
+ "secondarySalesPersonName": "",
62
+ "secondarySalesPersonEmail": null */
63
63
  },
64
64
  branch_details: data.branch_details,
65
65
  /* branch_details: {
66
- "active_branch_business_hours": "8:00 AM - 4:30 PM",
67
- "active_branch_email": "OrdersHarrisburg@bel-aqua.com",
68
- "active_branch_location": "Elizabethtown,PA",
69
- "active_branch_name": "BEL-AQUA HARRISBURG",
70
- "active_branch_phone": "(717)-689-3314",
71
- "active_brand_name": "BEL-AQUA"
72
- }, */
66
+ "active_branch_business_hours": "8:00 AM - 4:30 PM",
67
+ "active_branch_email": "OrdersHarrisburg@bel-aqua.com",
68
+ "active_branch_location": "Elizabethtown,PA",
69
+ "active_branch_name": "BEL-AQUA HARRISBURG",
70
+ "active_branch_phone": "(717)-689-3314",
71
+ "active_brand_name": "BEL-AQUA"
72
+ }, */
73
73
  user_query: lastUserMessage,
74
74
  session_id: data.session_id || data.session || sessionId,
75
75
  conversation_start_time: conversationStartTime,
76
76
  // /* customer_name: "Cristin Connerney",
77
- user_UUID: data.user_id || "mobile_user_unspecified",
78
- device: "mobile",
79
- window_location: "mobile"
77
+ user_UUID: data.user_id || 'mobile_user_unspecified',
78
+ device: 'mobile',
79
+ window_location: 'mobile'
80
80
  };
81
81
  const wsRef = (0, _react.useRef)(null);
82
82
  (0, _react.useEffect)(() => {
@@ -87,27 +87,27 @@ function useWebSocketMessage() {
87
87
  const ws = new WebSocket(socketUrl);
88
88
  wsRef.current = ws;
89
89
  ws.onopen = () => {
90
- console.log("WebSocket connection established.");
90
+ console.log('WebSocket connection established.');
91
91
  ws.send(JSON.stringify(payload));
92
92
  };
93
93
  ws.onmessage = event => {
94
94
  var _response$resource_de, _response$resource_de2;
95
95
  const response = JSON.parse(event.data);
96
- if (response.type !== "chunk") {
96
+ if (response.type !== 'chunk') {
97
97
  console.log(JSON.stringify(response, null, 2));
98
98
  }
99
99
  switch (response.type) {
100
100
  case 'middle_message':
101
101
  const middleMessage = {
102
- type: "middle",
102
+ type: 'middle',
103
103
  text: response.message,
104
104
  products: [],
105
- product_cards: "False"
105
+ product_cards: 'False'
106
106
  };
107
107
  setMessages([...messages, middleMessage]);
108
108
  break;
109
109
  case 'message':
110
- if (response.product_cards == "False" || response.product_cards == false) {
110
+ if (response.product_cards == 'False' || response.product_cards == false) {
111
111
  setGhostMessage(false);
112
112
  setTypingIndicator(false);
113
113
  } else {
@@ -115,14 +115,14 @@ function useWebSocketMessage() {
115
115
  setGhostCard(true);
116
116
  }
117
117
  const newMessage = {
118
- type: "ai",
118
+ type: 'ai',
119
119
  message_id: response.message_id || '',
120
120
  text: response.message,
121
- feedback: "True",
121
+ feedback: 'True',
122
122
  products: [],
123
- product_cards: response.product_cards || "False",
124
- 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) ?? "",
125
- 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) ?? ""
123
+ product_cards: response.product_cards || 'False',
124
+ 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) ?? '',
125
+ 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) ?? ''
126
126
  };
127
127
  setMessages(prevMessages => [...prevMessages, newMessage]);
128
128
  setLastMessageId(response.message_id);
@@ -131,19 +131,19 @@ function useWebSocketMessage() {
131
131
  const newContent = response.chunk;
132
132
  const newMessageId = response.message_id;
133
133
  setMessages(prevMessages => {
134
- if (prevMessages.length > 0 && prevMessages[prevMessages.length - 1].type === "ai") {
134
+ if (prevMessages.length > 0 && prevMessages[prevMessages.length - 1].type === 'ai') {
135
135
  return prevMessages.map((message, index) => index === prevMessages.length - 1 ? {
136
136
  ...message,
137
137
  text: message.text + newContent,
138
138
  message_id: newMessageId || message.message_id,
139
- feedback: "True"
139
+ feedback: 'True'
140
140
  } : message);
141
141
  } else {
142
142
  return [...prevMessages, {
143
- type: "ai",
143
+ type: 'ai',
144
144
  text: newContent,
145
145
  message_id: newMessageId,
146
- feedback: "True"
146
+ feedback: 'True'
147
147
  }];
148
148
  }
149
149
  });
@@ -153,13 +153,14 @@ function useWebSocketMessage() {
153
153
  }
154
154
  break;
155
155
  case 'product_cards':
156
+ console.log('\n\n\n\nthis is for my own sanity: ', response.products[0], '\n\n\n\n');
156
157
  setMessages(prevMessages => {
157
158
  const lastMessageIndex = prevMessages.length - 1;
158
- if (prevMessages[lastMessageIndex] && prevMessages[lastMessageIndex].type === "ai") {
159
+ if (prevMessages[lastMessageIndex] && prevMessages[lastMessageIndex].type === 'ai') {
159
160
  const expandedProducts = response.products.map(prod => ({
160
- part_number: prod.part_number || "",
161
+ part_number: prod.part_number || '',
161
162
  inventory_info: prod.inventory_info ? {
162
- default_uom: prod.inventory_info.default_uom || "",
163
+ default_uom: prod.inventory_info.default_uom || '',
163
164
  is_valid: prod.inventory_info.is_valid || false,
164
165
  info_by_uom: prod.inventory_info.info_by_uom ? Object.keys(prod.inventory_info.info_by_uom).reduce((acc, key) => {
165
166
  const value = prod.inventory_info.info_by_uom[key] || {};
@@ -175,25 +176,25 @@ function useWebSocketMessage() {
175
176
  }, {}) : {}
176
177
  } : {},
177
178
  product_details: prod.product_details ? {
178
- brand: prod.product_details.brand || "",
179
- flow: prod.product_details.flow || "",
180
- heritage_link: prod.product_details.heritage_link || "",
181
- image_url: prod.product_details.image_url || "",
182
- is_pump: prod.product_details.is_pump || "",
183
- manufacturer_id: prod.product_details.manufacturer_id || "",
184
- mfg_number: prod.product_details.mfg_number || "",
185
- part_number: prod.product_details.part_number || "",
186
- product_description: prod.product_details.product_description || "",
187
- product_name: prod.product_details.product_name || "",
188
- type: prod.product_details.type || "",
189
- vertical: prod.product_details.vertical || "",
190
- sku: prod.product_details.sku || ""
179
+ brand: prod.product_details.brand || '',
180
+ flow: prod.product_details.flow || '',
181
+ heritage_link: prod.product_details.heritage_link || '',
182
+ image_url: prod.product_details.image_url || '',
183
+ is_pump: prod.product_details.is_pump || '',
184
+ manufacturer_id: prod.product_details.manufacturer_id || '',
185
+ mfg_number: prod.product_details.mfg_number || '',
186
+ part_number: prod.product_details.part_number || '',
187
+ product_description: prod.product_details.product_description || '',
188
+ product_name: prod.product_details.product_name || '',
189
+ type: prod.product_details.type || '',
190
+ vertical: prod.product_details.vertical || '',
191
+ sku: prod.product_details.sku || ''
191
192
  } : {}
192
193
  }));
193
194
  const updatedLastMessage = {
194
195
  ...prevMessages[lastMessageIndex],
195
196
  products: expandedProducts,
196
- product_cards: "True"
197
+ product_cards: 'True'
197
198
  };
198
199
  return [...prevMessages.slice(0, lastMessageIndex), updatedLastMessage];
199
200
  }
@@ -206,12 +207,12 @@ function useWebSocketMessage() {
206
207
  case 'product_document':
207
208
  setMessages(prevMessages => {
208
209
  const lastMessageIndex = prevMessages.length - 1;
209
- if (prevMessages[lastMessageIndex] && prevMessages[lastMessageIndex].type === "ai") {
210
+ if (prevMessages[lastMessageIndex] && prevMessages[lastMessageIndex].type === 'ai') {
210
211
  var _response$resource_de3, _response$resource_de4;
211
212
  const updatedLastMessage = {
212
213
  ...prevMessages[lastMessageIndex],
213
- 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) ?? "",
214
- 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) ?? ""
214
+ 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) ?? '',
215
+ 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) ?? ''
215
216
  };
216
217
  return [...prevMessages.slice(0, lastMessageIndex), updatedLastMessage];
217
218
  }
@@ -223,7 +224,7 @@ function useWebSocketMessage() {
223
224
  case 'suggested_questions':
224
225
  setMessages(prevMessages => {
225
226
  const lastMessageIndex = prevMessages.length - 1;
226
- if (prevMessages[lastMessageIndex] && prevMessages[lastMessageIndex].type === "ai") {
227
+ if (prevMessages[lastMessageIndex] && prevMessages[lastMessageIndex].type === 'ai') {
227
228
  const updatedLastMessage = {
228
229
  ...prevMessages[lastMessageIndex],
229
230
  suggested_questions: true,
@@ -247,7 +248,7 @@ function useWebSocketMessage() {
247
248
  setGhostCard(false);
248
249
  };
249
250
  ws.onclose = event => {
250
- console.log("WebSocket connection closed:", event.reason);
251
+ console.log('WebSocket connection closed:', event.reason);
251
252
  setStartStreaming(false);
252
253
  setGhostMessage(false);
253
254
  setTypingIndicator(false);
@@ -257,7 +258,6 @@ function useWebSocketMessage() {
257
258
  ws.close();
258
259
  };
259
260
  }
260
- ;
261
261
  }, [startStreaming]);
262
262
  (0, _react.useEffect)(() => {
263
263
  if (wsRef.current && wsRef.current.readyState === WebSocket.OPEN) {
@@ -270,4 +270,329 @@ function useWebSocketMessage() {
270
270
  }
271
271
  }, [stopActivated, setStartStreaming]);
272
272
  }
273
+
274
+ // import React, { useState, useEffect, useRef, useContext } from 'react';
275
+ // import { AppContext } from '../contexts/AppContext';
276
+ //
277
+ // export function useWebSocketMessage() {
278
+ // const {
279
+ // setIsComplete,
280
+ // startStreaming,
281
+ // setMessages,
282
+ // messages,
283
+ // setGhostMessage,
284
+ // data,
285
+ // setTypingIndicator,
286
+ // setStartStreaming,
287
+ // lastUserMessage,
288
+ // stopActivated,
289
+ // sessionId,
290
+ // setGhostCard,
291
+ // BASE_URL,
292
+ // setStopActivated,
293
+ // setLastMessageId,
294
+ // conversationStartTime,
295
+ // } = useContext(AppContext);
296
+ //
297
+ // const wsProtocol = 'wss://';
298
+ // const wsUrl = BASE_URL.replace(/^http(s)?:\/\//, '');
299
+ // const ENDPOINT = '/send/event';
300
+ //
301
+ // const payload = {
302
+ // customer_code: data.customer_code,
303
+ // branch_code: data.branch_code,
304
+ // branch_full_name: data.branch_full_name,
305
+ // customer_token: data.customer_token,
306
+ // active_ship_to_information: {
307
+ // shipToId: data.active_ship_to,
308
+ // },
309
+ // branch_details: data.branch_details,
310
+ // user_query: lastUserMessage,
311
+ // session_id: data.session_id || data.session || sessionId,
312
+ // conversation_start_time: conversationStartTime,
313
+ // user_UUID: data.user_id || 'mobile_user_unspecified',
314
+ // device: 'mobile',
315
+ // window_location: 'mobile',
316
+ // };
317
+ //
318
+ // const wsRef = useRef(null);
319
+ //
320
+ // useEffect(() => {
321
+ // if (startStreaming) {
322
+ // console.log(payload, BASE_URL);
323
+ // const socketUrl = `${wsProtocol}${wsUrl}${ENDPOINT}`;
324
+ // console.log(socketUrl);
325
+ //
326
+ // const ws = new WebSocket(socketUrl);
327
+ // wsRef.current = ws;
328
+ //
329
+ // ws.onopen = () => {
330
+ // console.log('WebSocket connection established.');
331
+ // ws.send(JSON.stringify(payload));
332
+ // };
333
+ //
334
+ // ws.onmessage = event => {
335
+ // const response = JSON.parse(event.data);
336
+ //
337
+ // if (response.type !== 'chunk') {
338
+ // console.log(JSON.stringify(response, null, 2));
339
+ // }
340
+ // switch (response.type) {
341
+ // case 'middle_message':
342
+ // const middleMessage = {
343
+ // type: 'middle',
344
+ // text: response.message,
345
+ // products: [],
346
+ // product_cards: 'False',
347
+ // };
348
+ // setMessages(prevMessages => [...prevMessages, middleMessage]);
349
+ // break;
350
+ // case 'message':
351
+ // if (
352
+ // response.product_cards == 'False' ||
353
+ // response.product_cards == false
354
+ // ) {
355
+ // setGhostMessage(false);
356
+ // setTypingIndicator(false);
357
+ // } else {
358
+ // setGhostMessage(false);
359
+ // setGhostCard(true);
360
+ // }
361
+ // const newMessage = {
362
+ // type: 'ai',
363
+ // message_id: response.message_id || '',
364
+ // text: response.message,
365
+ // feedback: 'True',
366
+ // products: [],
367
+ // product_cards: response.product_cards || 'False',
368
+ // resource: response?.resource_details?.[0]?.link ?? '',
369
+ // resource_type: response?.resource_details?.[0]?.type ?? '',
370
+ // };
371
+ // setMessages(prevMessages => [...prevMessages, newMessage]);
372
+ // setLastMessageId(response.message_id);
373
+ // break;
374
+ // case 'chunk':
375
+ // const newContent = response.chunk;
376
+ // const newMessageId = response.message_id;
377
+ //
378
+ // setMessages(prevMessages => {
379
+ // if (
380
+ // prevMessages.length > 0 &&
381
+ // prevMessages[prevMessages.length - 1].type === 'ai'
382
+ // ) {
383
+ // return prevMessages.map((message, index) =>
384
+ // index === prevMessages.length - 1
385
+ // ? {
386
+ // ...message,
387
+ // text: message.text + newContent,
388
+ // message_id: newMessageId || message.message_id,
389
+ // feedback: 'True',
390
+ // }
391
+ // : message,
392
+ // );
393
+ // } else {
394
+ // return [
395
+ // ...prevMessages,
396
+ // {
397
+ // type: 'ai',
398
+ // text: newContent,
399
+ // message_id: newMessageId,
400
+ // feedback: 'True',
401
+ // },
402
+ // ];
403
+ // }
404
+ // });
405
+ // setGhostMessage(false);
406
+ // if (newMessageId) {
407
+ // setLastMessageId(newMessageId);
408
+ // }
409
+ // break;
410
+ // case 'product_cards':
411
+ // console.log('🛒 PRODUCT_CARDS RECEIVED:', response);
412
+ // setMessages(prevMessages => {
413
+ // console.log(
414
+ // '📦 Current messages array length:',
415
+ // prevMessages.length,
416
+ // );
417
+ // const lastMessageIndex = prevMessages.length - 1;
418
+ //
419
+ // if (lastMessageIndex < 0) {
420
+ // console.warn('⚠️ No messages exist yet!');
421
+ // return prevMessages;
422
+ // }
423
+ //
424
+ // const lastMessage = prevMessages[lastMessageIndex];
425
+ // console.log('📝 Last message:', {
426
+ // type: lastMessage?.type,
427
+ // message_id: lastMessage?.message_id,
428
+ // has_products: !!lastMessage?.products,
429
+ // text_preview: lastMessage?.text?.substring(0, 50),
430
+ // });
431
+ //
432
+ // if (lastMessage && lastMessage.type === 'ai') {
433
+ // const expandedProducts = response.products.map(prod => ({
434
+ // part_number: prod.part_number || '',
435
+ // inventory_info: prod.inventory_info
436
+ // ? {
437
+ // default_uom: prod.inventory_info.default_uom || '',
438
+ // is_valid: prod.inventory_info.is_valid || false,
439
+ // info_by_uom: prod.inventory_info.info_by_uom
440
+ // ? Object.keys(prod.inventory_info.info_by_uom).reduce(
441
+ // (acc, key) => {
442
+ // const value =
443
+ // prod.inventory_info.info_by_uom[key] || {};
444
+ // acc[key] = {
445
+ // gross_price: value.gross_price ?? 0,
446
+ // net_price: value.net_price ?? 0,
447
+ // is_on_sale: value.is_on_sale ?? false,
448
+ // quantity_available:
449
+ // value.quantity_available ?? 0,
450
+ // discounts: value.discounts ?? null,
451
+ // min_pack_qty: value.min_pack_qty ?? 0,
452
+ // };
453
+ // return acc;
454
+ // },
455
+ // {},
456
+ // )
457
+ // : {},
458
+ // }
459
+ // : {},
460
+ // product_details: prod.product_details
461
+ // ? {
462
+ // brand: prod.product_details.brand || '',
463
+ // flow: prod.product_details.flow || '',
464
+ // heritage_link: prod.product_details.heritage_link || '',
465
+ // image_url: prod.product_details.image_url || '',
466
+ // is_pump: prod.product_details.is_pump || '',
467
+ // manufacturer_id:
468
+ // prod.product_details.manufacturer_id || '',
469
+ // mfg_number: prod.product_details.mfg_number || '',
470
+ // part_number: prod.product_details.part_number || '',
471
+ // product_description:
472
+ // prod.product_details.product_description || '',
473
+ // product_name: prod.product_details.product_name || '',
474
+ // type: prod.product_details.type || '',
475
+ // vertical: prod.product_details.vertical || '',
476
+ // sku: prod.product_details.sku || '',
477
+ // }
478
+ // : {},
479
+ // }));
480
+ //
481
+ // console.log(
482
+ // '✅ Merging',
483
+ // expandedProducts.length,
484
+ // 'products into last message',
485
+ // );
486
+ //
487
+ // const updatedLastMessage = {
488
+ // ...lastMessage,
489
+ // products: expandedProducts,
490
+ // product_cards: 'True',
491
+ // };
492
+ //
493
+ // const newMessages = [
494
+ // ...prevMessages.slice(0, lastMessageIndex),
495
+ // updatedLastMessage,
496
+ // ];
497
+ //
498
+ // console.log(
499
+ // '🎯 Updated message now has products:',
500
+ // updatedLastMessage.products.length,
501
+ // );
502
+ // return newMessages;
503
+ // }
504
+ //
505
+ // console.warn("⚠️ Last message is not AI type or doesn't exist");
506
+ // return prevMessages;
507
+ // });
508
+ //
509
+ // setGhostMessage(false);
510
+ // setTypingIndicator(false);
511
+ // setGhostCard(false);
512
+ // break;
513
+ // case 'product_document':
514
+ // setMessages(prevMessages => {
515
+ // const lastMessageIndex = prevMessages.length - 1;
516
+ // if (
517
+ // prevMessages[lastMessageIndex] &&
518
+ // prevMessages[lastMessageIndex].type === 'ai'
519
+ // ) {
520
+ // const updatedLastMessage = {
521
+ // ...prevMessages[lastMessageIndex],
522
+ // resource: response?.resource_details?.[0]?.link ?? '',
523
+ // resource_type: response?.resource_details?.[0]?.type ?? '',
524
+ // };
525
+ // return [
526
+ // ...prevMessages.slice(0, lastMessageIndex),
527
+ // updatedLastMessage,
528
+ // ];
529
+ // }
530
+ // // FIX: Always return prevMessages if condition not met
531
+ // return prevMessages;
532
+ // });
533
+ // setGhostMessage(false);
534
+ // setTypingIndicator(false);
535
+ // setGhostCard(false);
536
+ // break;
537
+ // case 'suggested_questions':
538
+ // setMessages(prevMessages => {
539
+ // const lastMessageIndex = prevMessages.length - 1;
540
+ // if (
541
+ // prevMessages[lastMessageIndex] &&
542
+ // prevMessages[lastMessageIndex].type === 'ai'
543
+ // ) {
544
+ // const updatedLastMessage = {
545
+ // ...prevMessages[lastMessageIndex],
546
+ // suggested_questions: true,
547
+ // questions: response.suggested_questions,
548
+ // };
549
+ // return [
550
+ // ...prevMessages.slice(0, lastMessageIndex),
551
+ // updatedLastMessage,
552
+ // ];
553
+ // }
554
+ // // FIX: Always return prevMessages if condition not met
555
+ // return prevMessages;
556
+ // });
557
+ // break;
558
+ // case 'setComplete':
559
+ // setTypingIndicator(false);
560
+ // setStartStreaming(false);
561
+ // setGhostCard(false);
562
+ // break;
563
+ // }
564
+ // };
565
+ //
566
+ // ws.onerror = error => {
567
+ // setStartStreaming(false);
568
+ // setGhostMessage(false);
569
+ // setTypingIndicator(false);
570
+ // setGhostCard(false);
571
+ // };
572
+ //
573
+ // ws.onclose = event => {
574
+ // console.log('WebSocket connection closed:', event.reason);
575
+ // setStartStreaming(false);
576
+ // setGhostMessage(false);
577
+ // setTypingIndicator(false);
578
+ // setGhostCard(false);
579
+ // };
580
+ //
581
+ // return () => {
582
+ // ws.close();
583
+ // };
584
+ // }
585
+ // }, [startStreaming]);
586
+ //
587
+ // useEffect(() => {
588
+ // if (wsRef.current && wsRef.current.readyState === WebSocket.OPEN) {
589
+ // wsRef.current.close();
590
+ // setStartStreaming(false);
591
+ // setGhostMessage(false);
592
+ // setGhostCard(false);
593
+ // setTypingIndicator(false);
594
+ // setStopActivated(false);
595
+ // }
596
+ // }, [stopActivated, setStartStreaming]);
597
+ // }
273
598
  //# sourceMappingURL=Stream.js.map