impact-chatbot 2.3.2 → 2.3.4

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.
package/dist/index.esm.js CHANGED
@@ -23,14 +23,14 @@ import RefreshIcon from '@mui/icons-material/Refresh';
23
23
  import styled from 'styled-components';
24
24
  import { CircularProgress, Typography, Grid } from '@mui/material';
25
25
  import { fetchBaseUrl, replaceSpecialCharacter as replaceSpecialCharacter$1 } from 'core/Utils/functions/utils';
26
- import { ChatBotComponent } from 'impact-ui-chatbot';
27
- import { Button, Modal, Tabs, Slider, Select, DatePicker, Checkbox, RadioButtonGroup, Input, Loader } from 'impact-ui-v3';
26
+ import { Button, Modal, Tabs, Slider, Select, DatePicker, Checkbox, RadioButtonGroup, Input, Loader, ChatBotComponent } from 'impact-ui-v3';
28
27
  import AgGridComponent from 'core/Utils/agGrid';
29
28
  import agGridColumnFormatter from 'core/Utils/agGrid/column-formatter';
30
29
  import CoreChart from 'core/Utils/core-charts';
31
30
  import makeStyles$1 from '@mui/styles/makeStyles';
32
31
  import FormatListBulletedOutlinedIcon from '@mui/icons-material/FormatListBulletedOutlined';
33
32
  import PsychologyOutlinedIcon from '@mui/icons-material/PsychologyOutlined';
33
+ import { stopAgentFlow } from 'core/commonComponents/smartBot/services/chatbot-services';
34
34
  import RangePicker from 'core/commonComponents/dateRangePicker';
35
35
 
36
36
  /**
@@ -496,6 +496,16 @@ const parseResponse = (data, type, agentId = "", currentMode = "", disableTimeAn
496
496
  paramName: data?.data?.param_name
497
497
  }
498
498
  };
499
+ case "image":
500
+ return {
501
+ ...data,
502
+ timeStamp: timeString,
503
+ userType: "bot",
504
+ userName: userName,
505
+ headerTitle: data?.response_heading || "",
506
+ bodyType: "image",
507
+ bodyText: data?.image || data,
508
+ };
499
509
  case "combined":
500
510
  return {
501
511
  ...data,
@@ -1205,6 +1215,7 @@ const useAgentFlow = (dateFormat, chatDataRef, currentMode, setShowChatPlacehold
1205
1215
  setUniqueChatId: utilityObjectData?.setUniqueChatId,
1206
1216
  fieldNumber: utilityObjectData?.fieldNumber,
1207
1217
  setFieldNumber: utilityObjectData?.setFieldNumber,
1218
+ baseUrl: baseUrlTemp,
1208
1219
  };
1209
1220
  response = await parseResponse(null, "stream", "", currentModeValue, false, "", {}, payload, utilityObject);
1210
1221
  let chatDataMessages = chatDataInfoRef.current[currentModeValue].conversations[1].messages;
@@ -4338,6 +4349,13 @@ const useRectangleStyles = makeStyles((theme) => ({
4338
4349
  transition: "all 0.2s ease-in-out",
4339
4350
  position: "relative",
4340
4351
  overflow: "hidden",
4352
+ },
4353
+ rectangleHoverable: {
4354
+ cursor: "pointer",
4355
+ "&:hover": {
4356
+ transform: "translateY(-2px)",
4357
+ boxShadow: "0px 4px 12px rgba(0, 0, 0, 0.1)",
4358
+ },
4341
4359
  "&::before": {
4342
4360
  content: '""',
4343
4361
  position: "absolute",
@@ -4412,9 +4430,9 @@ const useRectangleStyles = makeStyles((theme) => ({
4412
4430
  color: "#60697D",
4413
4431
  },
4414
4432
  }));
4415
- const Rectangle = ({ type, icon, title, description, onClick }) => {
4433
+ const Rectangle = ({ type, icon, title, description, onClick, hoverable }) => {
4416
4434
  const classes = useRectangleStyles();
4417
- return (jsx("div", { className: `${classes.rectangle} ${classes[type]}`, onClick: onClick, children: jsxs("div", { className: classes.textContainer, children: [jsx(Typography, { className: classes.title, children: title }), jsx(Typography, { className: classes.description, children: description })] }) }));
4435
+ return (jsx("div", { className: `${classes.rectangle} ${classes[type]} ${hoverable ? classes.rectangleHoverable : ''}`, onClick: onClick, children: jsxs("div", { className: classes.textContainer, children: [jsx(Typography, { className: classes.title, children: title }), jsx(Typography, { className: classes.description, children: description })] }) }));
4418
4436
  };
4419
4437
  const ChatPlaceholder = (props) => {
4420
4438
  const { dateFormat, chatDataRef, currentMode, setShowChatPlaceholder, setLoader, setCurrentAgentId, baseUrl, setBaseUrl, setCurrentSessionId, customChatConfig, chatDataInfoRef, setChatDataState, userInput, legacyAgentScreen, activeConversationId, chatBodyRef, chatbotContext, setInitValue, setSessionId, thinkingContent, setThinkingContent, isThinking, setIsThinking, chatId, setChatId, isStop, setIsStop, functionsRef, functionsState, setFunctionsState, thinkingHeaderMessage, setThinkingHeaderMessage, uniqueChatId, setUniqueChatId, } = props;
@@ -4479,15 +4497,15 @@ const ChatPlaceholder = (props) => {
4479
4497
  useEffect(() => {
4480
4498
  getBaseUrl();
4481
4499
  }, []);
4482
- const handleRectangleClick = (agentId) => {
4500
+ const handleRectangleClick = (agentId, title) => {
4483
4501
  if (legacyAgentScreen) {
4484
4502
  setCurrentAgentId(agentId);
4485
4503
  const initiateAgentPayload = {
4486
4504
  agent_id: agentId,
4487
4505
  session_id: null,
4488
- user_input: userInput,
4506
+ user_input: title,
4489
4507
  init: true,
4490
- delay: 0,
4508
+ delay: 0.3,
4491
4509
  };
4492
4510
  setAgentFlow(initiateAgentPayload, "", baseUrl);
4493
4511
  }
@@ -4529,7 +4547,7 @@ const ChatPlaceholder = (props) => {
4529
4547
  agentId: card.agentId || card.id
4530
4548
  }));
4531
4549
  const dataToMap = legacyAgentScreen ? transformedCardList : rectangleData;
4532
- return (jsxs("div", { className: classes.placeholderContainer, children: [jsx("div", { className: classes.centerIconContainer, children: jsx(SvgCenter3D, { className: classes.centerIcon }) }), jsx(Typography, { variant: "h1", className: classes.heading, children: "Alan's Capabilities" }), jsx(Typography, { variant: "body1", className: classes.headingHelperText, children: "Discover potential issues & opportunities Alan can help you with!" }), jsx("div", { className: classes.rectanglesContainer, children: dataToMap.map((item, index) => (jsx(Rectangle, { type: item.type, icon: item.icon, title: item.title, description: item.description, onClick: () => handleRectangleClick(item.agentId) }, index))) })] }));
4550
+ return (jsxs("div", { className: classes.placeholderContainer, children: [jsx("div", { className: classes.centerIconContainer, children: jsx(SvgCenter3D, { className: classes.centerIcon }) }), jsx(Typography, { variant: "h1", className: classes.heading, children: "Alan's Capabilities" }), jsx(Typography, { variant: "body1", className: classes.headingHelperText, children: "Discover potential issues & opportunities Alan can help you with!" }), jsx("div", { className: classes.rectanglesContainer, children: dataToMap.map((item, index) => (jsx(Rectangle, { type: item.type, icon: item.icon, title: item.title, description: item.description, onClick: () => handleRectangleClick(item?.agentId, item?.title), hoverable: legacyAgentScreen }, index))) })] }));
4533
4551
  };
4534
4552
 
4535
4553
  const dateFormat = "DD-MM-YYYY HH:mm:ss";
@@ -5012,6 +5030,13 @@ const sseevent = (message, messageToStoreRef) => {
5012
5030
  };
5013
5031
  }
5014
5032
  }
5033
+ if (messageToStoreRef.current.currentMode === "agent" &&
5034
+ (parsedData?.chat_id || parsedData?.session_id)) {
5035
+ messageToStoreRef.current.uniqueChatId = parsedData?.chat_id
5036
+ ? parsedData.chat_id
5037
+ : "";
5038
+ messageToStoreRef.current.sessionId = parsedData?.session_id;
5039
+ }
5015
5040
  if (parsedData?.is_error) {
5016
5041
  messageToStoreRef.current.chatData.response =
5017
5042
  messageToStoreRef.current.chatData.response +
@@ -5079,6 +5104,21 @@ const sseevent = (message, messageToStoreRef) => {
5079
5104
  : "";
5080
5105
  messageToStoreRef.current.status = parsedData?.status;
5081
5106
  }
5107
+ // Handle image chunks for navigation mode
5108
+ if (parsedData?.response_type === "image" &&
5109
+ messageToStoreRef.current.currentMode === "navigation") {
5110
+ let imageData = {
5111
+ type: "image",
5112
+ image: parsedData.image,
5113
+ response_heading: parsedData.response_heading,
5114
+ };
5115
+ let previousData = isArray$1(messageToStoreRef.current.appendedData)
5116
+ ? messageToStoreRef.current.appendedData
5117
+ : isEmpty$1(messageToStoreRef.current.appendedData)
5118
+ ? []
5119
+ : [messageToStoreRef.current.appendedData];
5120
+ messageToStoreRef.current.appendedData = [...previousData, imageData];
5121
+ }
5082
5122
  return new MessageEvent(type, { data: data });
5083
5123
  }
5084
5124
  catch (error) {
@@ -5551,7 +5591,7 @@ const formatThinkingTime = (seconds) => {
5551
5591
  * @param {Function} botData.utilityObject.setChatDataState - Function to update chat data state
5552
5592
  */
5553
5593
  const StreamedContent = ({ botData }) => {
5554
- const { activeConversationId, currentMode, chatDataRef, chatBodyRef, setChatDataState, chatDataInfoRef, setLoader = (params) => { }, processResponse = (params) => { }, setThinkingContent, thinkingContent, isThinking: isThinkingFromParent, setIsThinking: setIsThinkingFromParent, chatId, setChatId, isStop, setIsStop, functionsRef, functionsState, setFunctionsState, thinkingHeaderMessage, setThinkingHeaderMessage, } = botData.utilityObject;
5594
+ const { activeConversationId, currentMode, chatDataRef, chatBodyRef, setChatDataState, chatDataInfoRef, setLoader = (params) => { }, processResponse = (params) => { }, setThinkingContent, thinkingContent, isThinking: isThinkingFromParent, setIsThinking: setIsThinkingFromParent, chatId, setChatId, isStop, setIsStop, functionsRef, functionsState, setFunctionsState, thinkingHeaderMessage, setThinkingHeaderMessage, baseUrl } = botData.utilityObject;
5555
5595
  const classes = useStyles$3();
5556
5596
  useStyles$6();
5557
5597
  const dispatch = useDispatch();
@@ -5611,6 +5651,7 @@ const StreamedContent = ({ botData }) => {
5611
5651
  thinkingHeading: botData?.utilityObject?.thinkingResponse?.thinkingHeading
5612
5652
  },
5613
5653
  },
5654
+ currentMode: currentMode,
5614
5655
  appendedData: {},
5615
5656
  appendedDataFromLastChunk: {},
5616
5657
  initValue: false,
@@ -6023,6 +6064,11 @@ const StreamedContent = ({ botData }) => {
6023
6064
  // // enableLikes: true
6024
6065
  // },
6025
6066
  ];
6067
+ let finalData = isArray(messageToStoreRef?.current?.appendedData)
6068
+ ? messageToStoreRef?.current?.appendedData
6069
+ : isEmpty(messageToStoreRef?.current?.appendedData)
6070
+ ? []
6071
+ : [messageToStoreRef?.current?.appendedData];
6026
6072
  let textResponseTobeParsed = {
6027
6073
  ...messageToStoreRef.current.chatData,
6028
6074
  type: "text",
@@ -6030,7 +6076,7 @@ const StreamedContent = ({ botData }) => {
6030
6076
  let response = {
6031
6077
  data: {
6032
6078
  data: {
6033
- data: [textResponseTobeParsed],
6079
+ data: [textResponseTobeParsed, ...finalData],
6034
6080
  },
6035
6081
  },
6036
6082
  };
@@ -6072,6 +6118,10 @@ const StreamedContent = ({ botData }) => {
6072
6118
  sourceRef.current.close();
6073
6119
  setIsStreaming(false);
6074
6120
  setIsStreamingDone(true);
6121
+ // Stop the agent flow on the backend
6122
+ if (messageToStoreRef.current.sessionId) {
6123
+ stopAgentFlow({ session_id: messageToStoreRef.current.sessionId }, baseUrl);
6124
+ }
6075
6125
  // Clear timeout if exists
6076
6126
  if (streamTimeoutRef.current) {
6077
6127
  clearTimeout(streamTimeoutRef.current);
@@ -6372,6 +6422,20 @@ const InputContent = ({ bodyText }) => {
6372
6422
  return (jsx("div", { style: { width: '100%', marginTop: '10px' }, children: jsx(Input, { label: label, placeholder: placeholder, value: value, onChange: handleChange, required: isRequired, disabled: isDisabled, type: inputType || "text", labelOrientation: labelOrientation, maxLength: maxLength, minLength: minLength }) }));
6373
6423
  };
6374
6424
 
6425
+ const ImageContent = ({ bodyText }) => {
6426
+ const { gcs_uri, caption } = bodyText || {};
6427
+ return (jsxs("div", { style: {
6428
+ display: "flex",
6429
+ flexDirection: "column",
6430
+ gap: "8px",
6431
+ width: "100%",
6432
+ }, children: [gcs_uri && (jsx("img", { src: gcs_uri, alt: caption || "Image", style: {
6433
+ maxWidth: "100%",
6434
+ borderRadius: "8px",
6435
+ objectFit: "contain",
6436
+ } })), caption && (jsx("div", { children: jsx(TextRenderer, { text: caption }) }))] }));
6437
+ };
6438
+
6375
6439
  const useStyles$1 = makeStyles$1((theme) => ({
6376
6440
  stepsContainer: {
6377
6441
  display: "flex",
@@ -6563,6 +6627,8 @@ const CombinedContent = ({ botData, props }) => {
6563
6627
  return jsx(ButtonContent, { bodyText: parsedData.bodyText }, key);
6564
6628
  case "input":
6565
6629
  return jsx(InputContent, { bodyText: parsedData.bodyText }, key);
6630
+ case "image":
6631
+ return jsx(ImageContent, { bodyText: parsedData.bodyText }, key);
6566
6632
  default:
6567
6633
  return null;
6568
6634
  }
@@ -6655,6 +6721,8 @@ const BotMessage = ({ botData, state, handleLikeDislike, props }) => {
6655
6721
  return jsx(ButtonContent, { bodyText: botData.bodyText });
6656
6722
  case "input":
6657
6723
  return jsx(InputContent, { bodyText: botData.bodyText });
6724
+ case "image":
6725
+ return jsx(ImageContent, { bodyText: botData.bodyText });
6658
6726
  case "combined":
6659
6727
  return jsx(CombinedContent, { botData: botData, props: props });
6660
6728
  case "dynamic":
@@ -9846,7 +9914,7 @@ const SmartBot = (props) => {
9846
9914
  setBaseUrl(customBaseUrl);
9847
9915
  }
9848
9916
  }, [forceOpen]);
9849
- return (jsxs("div", { className: `${classes.agentStyleOverride} ${partialClose ? classes.hideBotStyle : ""}`, children: [jsx(MemoryModal, { isModalOpen: isModalOpen, setIsModalOpen: setIsModalOpen, displaySnackMessages: displaySnackMessages }), jsx(UploadModal, { isUploadModalOpen: isUploadModalOpen, setIsUploadModalOpen: setIsUploadModalOpen, displaySnackMessages: displaySnackMessages }), jsx(ChatBotComponent, { isFullWidth: true, userName: userName, showHistoryPanel: false, customInputComponent: currentMode === "agent" ? (jsx(ChatbotInput, { newChatScreen: newChatScreen, inputValue: userInput, setInputValue: setUserInput, isStopIcon: isStop, onSendIconClick: onSendIconClick, onStopIconClick: onStopIconClick, currentMode: currentMode, filterOptions: filterOptions })) : null, isChatBotOpen: showModal || forceOpen,
9917
+ return (jsxs("div", { className: `${classes.agentStyleOverride} ${partialClose ? classes.hideBotStyle : ""}`, children: [jsx(MemoryModal, { isModalOpen: isModalOpen, setIsModalOpen: setIsModalOpen, displaySnackMessages: displaySnackMessages }), jsx(UploadModal, { isUploadModalOpen: isUploadModalOpen, setIsUploadModalOpen: setIsUploadModalOpen, displaySnackMessages: displaySnackMessages }), jsx(ChatBotComponent, { isFullWidth: forceOpen, userName: userName, showHistoryPanel: false, customInputComponent: currentMode === "agent" ? (jsx(ChatbotInput, { newChatScreen: newChatScreen, inputValue: userInput, setInputValue: setUserInput, isStopIcon: isStop, onSendIconClick: onSendIconClick, onStopIconClick: onStopIconClick, currentMode: currentMode, filterOptions: filterOptions })) : null, isChatBotOpen: showModal || forceOpen,
9850
9918
  // landingScreen={true}
9851
9919
  handleNewChatClick: () => {
9852
9920
  localStorage.setItem("isStreaming", "false");