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