impact-chatbot 2.3.19 → 2.3.20
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/hooks/useAgentFlow.d.ts +2 -2
- package/dist/hooks/useChatFlow.d.ts +2 -2
- package/dist/hooks/useChatState.d.ts +6 -2
- package/dist/hooks/useConversationManagement.d.ts +5 -5
- package/dist/index.cjs.js +711 -113
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +712 -114
- package/dist/index.esm.js.map +1 -1
- package/dist/temp.d.ts +71 -0
- package/dist/utlis.d.ts +6 -9
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -35,6 +35,7 @@ var globalStyles$1 = require('core/Styles/globalStyles');
|
|
|
35
35
|
var FormatListBulletedOutlinedIcon = require('@mui/icons-material/FormatListBulletedOutlined');
|
|
36
36
|
var PsychologyOutlinedIcon = require('@mui/icons-material/PsychologyOutlined');
|
|
37
37
|
var chatbotServices = require('core/commonComponents/smartBot/services/chatbot-services');
|
|
38
|
+
var SaveOutlinedIcon = require('@mui/icons-material/SaveOutlined');
|
|
38
39
|
var RangePicker = require('core/commonComponents/dateRangePicker');
|
|
39
40
|
|
|
40
41
|
function _interopNamespaceDefault(e) {
|
|
@@ -614,7 +615,7 @@ const handleMessageLike = async (question, liked, setLoadingState, displaySnackM
|
|
|
614
615
|
// question ===
|
|
615
616
|
// `${item?.response_heading || item?.screen_name}_${item?.timeStamp}`
|
|
616
617
|
// );
|
|
617
|
-
const activeMessage = chatDataInfoRef?.[currentMode]?.conversations?.[
|
|
618
|
+
const activeMessage = chatDataInfoRef?.[currentMode]?.conversations?.[activeConversationId]?.messages?.[chatIndex];
|
|
618
619
|
// const activeMessage = chats?.[currentMode].conversations[activeConversationId].messages[activeMessageIndex];
|
|
619
620
|
try {
|
|
620
621
|
let request;
|
|
@@ -640,7 +641,7 @@ const handleMessageLike = async (question, liked, setLoadingState, displaySnackM
|
|
|
640
641
|
// activeMessageIndex,
|
|
641
642
|
// () => updatedMessage
|
|
642
643
|
// );
|
|
643
|
-
chatDataInfoRef[currentMode].conversations[
|
|
644
|
+
chatDataInfoRef[currentMode].conversations[activeConversationId].messages[chatIndex] = updatedMessage;
|
|
644
645
|
// templateData[currentMode].conversations[activeConversationId].messages = newChats;
|
|
645
646
|
setChatDataState({ ...chatDataInfoRef });
|
|
646
647
|
localStorage.setItem("chatData", JSON.stringify(templateData));
|
|
@@ -739,34 +740,35 @@ const getDynamicFunction = async (path, functionName) => {
|
|
|
739
740
|
return null;
|
|
740
741
|
}
|
|
741
742
|
};
|
|
743
|
+
const generateConversationId = () => {
|
|
744
|
+
try {
|
|
745
|
+
return Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
|
|
746
|
+
}
|
|
747
|
+
catch (error) {
|
|
748
|
+
console.error("generateConversationId error", error);
|
|
749
|
+
return 0;
|
|
750
|
+
}
|
|
751
|
+
};
|
|
742
752
|
/**
|
|
743
753
|
* Generates a conversation object structure with empty messages array and current timestamp
|
|
744
754
|
* @returns {object} - The conversation object structure
|
|
745
755
|
*/
|
|
746
|
-
const generateConversationObject = () => {
|
|
756
|
+
const generateConversationObject = (conversationId) => {
|
|
747
757
|
try {
|
|
748
758
|
return {
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
timestamp: new Date().toISOString(),
|
|
754
|
-
messages: [],
|
|
755
|
-
},
|
|
756
|
-
},
|
|
759
|
+
id: conversationId,
|
|
760
|
+
name: `Conversation ${conversationId}`,
|
|
761
|
+
timestamp: new Date().toISOString(),
|
|
762
|
+
messages: [],
|
|
757
763
|
};
|
|
758
764
|
}
|
|
759
765
|
catch (error) {
|
|
760
766
|
console.error("generateConversationObject error", error);
|
|
761
767
|
return {
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
timestamp: new Date().toISOString(),
|
|
767
|
-
messages: [],
|
|
768
|
-
},
|
|
769
|
-
},
|
|
768
|
+
id: conversationId,
|
|
769
|
+
name: `Conversation ${conversationId}`,
|
|
770
|
+
timestamp: new Date().toISOString(),
|
|
771
|
+
messages: [],
|
|
770
772
|
};
|
|
771
773
|
}
|
|
772
774
|
};
|
|
@@ -963,6 +965,12 @@ const replaceSpecialCharToCharCode = (str) => {
|
|
|
963
965
|
// Convert pixels to rem
|
|
964
966
|
const pxToRem = (px) => `${px / 16}rem`;
|
|
965
967
|
|
|
968
|
+
// Get current user ID from session storage
|
|
969
|
+
const getCurrentUserId = () => {
|
|
970
|
+
const userDetails = JSON.parse(sessionStorage.getItem("userDetails") || "{}");
|
|
971
|
+
return userDetails?.user_id || null;
|
|
972
|
+
};
|
|
973
|
+
|
|
966
974
|
// Get user name from session storage
|
|
967
975
|
const getUserName = () => {
|
|
968
976
|
const userDetails = JSON.parse(sessionStorage.getItem("userDetails") || "{}");
|
|
@@ -1212,7 +1220,9 @@ const ThinkinHeaderInfo = (props) => {
|
|
|
1212
1220
|
// import { stackedBarChartExample } from "../examples/GraphExample";
|
|
1213
1221
|
// import { examplePieChartData } from "../examples/GraphExample";
|
|
1214
1222
|
const useAgentFlow = (dateFormat, chatDataRef, currentMode, setShowChatPlaceholder, setLoader, baseUrl = "", setCurrentSessionId = (params) => { }, customChatConfig = null, chatDataInfoRef = null, utilityObjectData = {}) => {
|
|
1215
|
-
const
|
|
1223
|
+
const { activeConversationId, setActiveConversationId } = utilityObjectData;
|
|
1224
|
+
const setAgentFlow = React.useCallback(async (payload, input = "", baseUrlTemp = "", conversationIdParam = null) => {
|
|
1225
|
+
let conversationId = conversationIdParam || activeConversationId;
|
|
1216
1226
|
try {
|
|
1217
1227
|
const currentTimeString = getCurrentDateTimeString(dateFormat);
|
|
1218
1228
|
const currentModeValue = localStorage.getItem("currentModeData") || currentMode;
|
|
@@ -1230,17 +1240,24 @@ const useAgentFlow = (dateFormat, chatDataRef, currentMode, setShowChatPlacehold
|
|
|
1230
1240
|
timeStamp: currentTimeString,
|
|
1231
1241
|
userType: "loader",
|
|
1232
1242
|
};
|
|
1233
|
-
if (isEmpty(chatDataInfoRef.current[currentModeValue])) {
|
|
1234
|
-
|
|
1235
|
-
|
|
1243
|
+
if (!conversationId || isEmpty(chatDataInfoRef.current[currentModeValue].conversations[conversationId])) {
|
|
1244
|
+
conversationId = generateConversationId();
|
|
1245
|
+
setActiveConversationId(conversationId);
|
|
1246
|
+
chatDataInfoRef.current[currentModeValue].conversations[conversationId] = generateConversationObject(conversationId);
|
|
1247
|
+
}
|
|
1248
|
+
// if (isEmpty(chatDataInfoRef.current[currentModeValue])) {
|
|
1249
|
+
// chatDataInfoRef.current[
|
|
1250
|
+
// currentModeValue
|
|
1251
|
+
// ] = generateConversationObject();
|
|
1252
|
+
// }
|
|
1236
1253
|
if (showUserChat) {
|
|
1237
1254
|
chatDataRef.current[currentModeValue] = [
|
|
1238
1255
|
...chatDataRef.current?.[currentModeValue],
|
|
1239
1256
|
userChat,
|
|
1240
1257
|
loaderData,
|
|
1241
1258
|
];
|
|
1242
|
-
chatDataInfoRef.current[currentModeValue].conversations[
|
|
1243
|
-
...chatDataInfoRef.current[currentModeValue].conversations[
|
|
1259
|
+
chatDataInfoRef.current[currentModeValue].conversations[conversationId].messages = [
|
|
1260
|
+
...chatDataInfoRef.current[currentModeValue].conversations[conversationId]
|
|
1244
1261
|
.messages,
|
|
1245
1262
|
userChat,
|
|
1246
1263
|
];
|
|
@@ -1258,7 +1275,7 @@ const useAgentFlow = (dateFormat, chatDataRef, currentMode, setShowChatPlacehold
|
|
|
1258
1275
|
let response = {};
|
|
1259
1276
|
if (utilityObjectData?.runStreaming) {
|
|
1260
1277
|
let utilityObject = {
|
|
1261
|
-
activeConversationId:
|
|
1278
|
+
activeConversationId: conversationId,
|
|
1262
1279
|
currentMode: currentModeValue,
|
|
1263
1280
|
chatDataRef,
|
|
1264
1281
|
chatBodyRef: utilityObjectData?.chatBodyRef,
|
|
@@ -1297,9 +1314,9 @@ const useAgentFlow = (dateFormat, chatDataRef, currentMode, setShowChatPlacehold
|
|
|
1297
1314
|
baseUrl: baseUrlTemp,
|
|
1298
1315
|
};
|
|
1299
1316
|
response = await parseResponse(null, "stream", "", currentModeValue, false, "", {}, payload, utilityObject);
|
|
1300
|
-
let chatDataMessages = chatDataInfoRef.current[currentModeValue].conversations[
|
|
1317
|
+
let chatDataMessages = chatDataInfoRef.current[currentModeValue].conversations[conversationId].messages;
|
|
1301
1318
|
chatDataMessages = [...chatDataMessages, response];
|
|
1302
|
-
chatDataInfoRef.current[currentModeValue].conversations[
|
|
1319
|
+
chatDataInfoRef.current[currentModeValue].conversations[conversationId].messages = chatDataMessages;
|
|
1303
1320
|
// Trigger re-render by updating chatDataState
|
|
1304
1321
|
if (utilityObjectData?.setChatDataState) {
|
|
1305
1322
|
utilityObjectData.setChatDataState({ ...chatDataRef.current });
|
|
@@ -1631,7 +1648,7 @@ const useAgentFlow = (dateFormat, chatDataRef, currentMode, setShowChatPlacehold
|
|
|
1631
1648
|
// data: tableResponse,
|
|
1632
1649
|
// },
|
|
1633
1650
|
// };
|
|
1634
|
-
processResponse(response, payload, currentModeValue, customChatConfig);
|
|
1651
|
+
processResponse(response, payload, currentModeValue, customChatConfig, {}, conversationId);
|
|
1635
1652
|
// let parsedResponse = {};
|
|
1636
1653
|
// let customParseResponse = null;
|
|
1637
1654
|
// // Check if a custom parser is provided and load it
|
|
@@ -1794,9 +1811,9 @@ const useAgentFlow = (dateFormat, chatDataRef, currentMode, setShowChatPlacehold
|
|
|
1794
1811
|
bodyType: "text",
|
|
1795
1812
|
};
|
|
1796
1813
|
const currentModeValue = localStorage.getItem("currentModeData") || currentMode;
|
|
1797
|
-
let chatDataMessages = chatDataInfoRef.current[currentModeValue].conversations[
|
|
1814
|
+
let chatDataMessages = chatDataInfoRef.current[currentModeValue].conversations[conversationId].messages;
|
|
1798
1815
|
chatDataMessages = [...chatDataMessages, failResponseText];
|
|
1799
|
-
chatDataInfoRef.current[currentModeValue].conversations[
|
|
1816
|
+
chatDataInfoRef.current[currentModeValue].conversations[conversationId].messages = chatDataMessages;
|
|
1800
1817
|
chatDataRef.current[currentMode] = [
|
|
1801
1818
|
...chatDataRef.current[currentMode]?.filter((data) => data.userType !== "loader"),
|
|
1802
1819
|
failResponseText,
|
|
@@ -1807,7 +1824,7 @@ const useAgentFlow = (dateFormat, chatDataRef, currentMode, setShowChatPlacehold
|
|
|
1807
1824
|
}
|
|
1808
1825
|
setLoader(false);
|
|
1809
1826
|
}
|
|
1810
|
-
}, [currentMode, chatDataRef, baseUrl, customChatConfig, utilityObjectData?.thinkingContent]);
|
|
1827
|
+
}, [currentMode, chatDataRef, baseUrl, customChatConfig, utilityObjectData?.thinkingContent, activeConversationId]);
|
|
1811
1828
|
const prepareDataAndSendToAgent = React.useCallback((data, init = false, utilityObjectData) => {
|
|
1812
1829
|
try {
|
|
1813
1830
|
let payload = {};
|
|
@@ -1851,13 +1868,15 @@ const useAgentFlow = (dateFormat, chatDataRef, currentMode, setShowChatPlacehold
|
|
|
1851
1868
|
}
|
|
1852
1869
|
dispatch(setChatbotContext({}));
|
|
1853
1870
|
}
|
|
1854
|
-
|
|
1871
|
+
// Get activeConversationId from utilityObjectData if available, otherwise use the one from closure
|
|
1872
|
+
const currentConversationId = utilityObjectData?.activeConversationId || activeConversationId;
|
|
1873
|
+
setAgentFlow(payload, "", data?.baseUrl, currentConversationId);
|
|
1855
1874
|
}
|
|
1856
1875
|
catch (error) {
|
|
1857
1876
|
console.error("Error in prepareDataAndSendToAgent: ", error);
|
|
1858
1877
|
}
|
|
1859
|
-
}, []);
|
|
1860
|
-
const processResponse = React.useCallback(async (response, payload, currentModeValue, customChatConfig, utilsObject) => {
|
|
1878
|
+
}, [activeConversationId, setAgentFlow]);
|
|
1879
|
+
const processResponse = React.useCallback(async (response, payload, currentModeValue, customChatConfig, utilsObject, conversationId) => {
|
|
1861
1880
|
try {
|
|
1862
1881
|
let parsedResponse = {};
|
|
1863
1882
|
let customParseResponse = null;
|
|
@@ -1959,7 +1978,7 @@ const useAgentFlow = (dateFormat, chatDataRef, currentMode, setShowChatPlacehold
|
|
|
1959
1978
|
if (utilsObject?.newChatData) {
|
|
1960
1979
|
chatDataInfoRef.current = utilsObject?.newChatData.current;
|
|
1961
1980
|
}
|
|
1962
|
-
let chatDataMessages = chatDataInfoRef.current[currentModeValue].conversations[
|
|
1981
|
+
let chatDataMessages = chatDataInfoRef.current[currentModeValue].conversations[conversationId].messages;
|
|
1963
1982
|
let finalParsedResponse = isArray(parsedResponse)
|
|
1964
1983
|
? parsedResponse
|
|
1965
1984
|
: [parsedResponse];
|
|
@@ -1967,7 +1986,7 @@ const useAgentFlow = (dateFormat, chatDataRef, currentMode, setShowChatPlacehold
|
|
|
1967
1986
|
message.firstMessage = index === 0 ? true : false;
|
|
1968
1987
|
});
|
|
1969
1988
|
chatDataMessages = [...chatDataMessages, ...(Array.isArray(finalParsedResponse) ? finalParsedResponse : [])];
|
|
1970
|
-
chatDataInfoRef.current[currentModeValue].conversations[
|
|
1989
|
+
chatDataInfoRef.current[currentModeValue].conversations[conversationId].messages = chatDataMessages;
|
|
1971
1990
|
// Trigger re-render by updating chatDataState
|
|
1972
1991
|
if (utilityObjectData?.setChatDataState) {
|
|
1973
1992
|
utilityObjectData.setChatDataState({ ...chatDataRef.current });
|
|
@@ -1987,7 +2006,7 @@ const useAgentFlow = (dateFormat, chatDataRef, currentMode, setShowChatPlacehold
|
|
|
1987
2006
|
};
|
|
1988
2007
|
};
|
|
1989
2008
|
|
|
1990
|
-
const useChatFlow = (chatDataRef, setLoader, setFlowType, setScreenName, setUserInput, setQuestionIndex, setCurrentAppLink, flowType, screenName, questionIndex, userInput, dateFormat, currentMode, activeConversationId, setIsModuleChanged, chatBodyRef, filterReducerState, dispatch, navigate, setShowChatPlaceholder, baseUrl, setChatDataState, setCurrentSessionId, customChatConfig, chatDataInfoRef, chatbotContext, setInitValue, setSessionId, thinkingContent, setThinkingContent, isThinking, setIsThinking, chatId, setChatId, isStop, setIsStop, functionsRef, functionsState, setFunctionsState, thinkingHeaderMessage, setThinkingHeaderMessage, uniqueChatId, initValue, sessionId, fieldNumber, setFieldNumber, additionalArgs) => {
|
|
2009
|
+
const useChatFlow = (chatDataRef, setLoader, setFlowType, setScreenName, setUserInput, setQuestionIndex, setCurrentAppLink, flowType, screenName, questionIndex, userInput, dateFormat, currentMode, activeConversationId, setIsModuleChanged, chatBodyRef, filterReducerState, dispatch, navigate, setShowChatPlaceholder, baseUrl, setChatDataState, setCurrentSessionId, customChatConfig, chatDataInfoRef, chatbotContext, setInitValue, setSessionId, thinkingContent, setThinkingContent, isThinking, setIsThinking, chatId, setChatId, isStop, setIsStop, functionsRef, functionsState, setFunctionsState, thinkingHeaderMessage, setThinkingHeaderMessage, uniqueChatId, initValue, sessionId, fieldNumber, setFieldNumber, additionalArgs, setActiveConversationId) => {
|
|
1991
2010
|
const { prepareDataAndSendToAgent, setAgentFlow, processResponse, } = useAgentFlow(dateFormat, chatDataRef, currentMode, setShowChatPlaceholder, setLoader, baseUrl, setCurrentSessionId, customChatConfig, chatDataInfoRef, {
|
|
1992
2011
|
setChatDataState,
|
|
1993
2012
|
activeConversationId,
|
|
@@ -2183,12 +2202,11 @@ const useChatFlow = (chatDataRef, setLoader, setFlowType, setScreenName, setUser
|
|
|
2183
2202
|
setUserInput(data.displayText);
|
|
2184
2203
|
}
|
|
2185
2204
|
else {
|
|
2186
|
-
fetchUserResultsFromQuery(data, true);
|
|
2205
|
+
fetchUserResultsFromQuery(data, true, "", activeConversationId);
|
|
2187
2206
|
}
|
|
2188
2207
|
}, [activeConversationId, baseUrl]);
|
|
2189
|
-
const fetchUserResultsFromQuery = React.useCallback(async (refObject, fetchQuestions = false, inputValue = userInput) => {
|
|
2208
|
+
const fetchUserResultsFromQuery = React.useCallback(async (refObject, fetchQuestions = false, inputValue = userInput, conversationId = activeConversationId) => {
|
|
2190
2209
|
let flowType = refObject?.flow_type ? refObject?.flow_type : currentMode;
|
|
2191
|
-
ensureConversationExists(flowType, activeConversationId, chatDataRef);
|
|
2192
2210
|
const currentTimeString = getCurrentDateTimeString();
|
|
2193
2211
|
const input = fetchQuestions ? refObject?.screen_name : inputValue;
|
|
2194
2212
|
setUserInput("");
|
|
@@ -2205,16 +2223,21 @@ const useChatFlow = (chatDataRef, setLoader, setFlowType, setScreenName, setUser
|
|
|
2205
2223
|
timeStamp: currentTimeString,
|
|
2206
2224
|
userType: "loader",
|
|
2207
2225
|
};
|
|
2208
|
-
if (lodash.isEmpty(chatDataInfoRef.current[currentMode])) {
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2226
|
+
if (!conversationId || lodash.isEmpty(chatDataInfoRef.current[currentMode].conversations[conversationId])) {
|
|
2227
|
+
conversationId = generateConversationId();
|
|
2228
|
+
setActiveConversationId(conversationId);
|
|
2229
|
+
chatDataInfoRef.current[currentMode].conversations[conversationId] = generateConversationObject(conversationId);
|
|
2230
|
+
}
|
|
2231
|
+
// Ensure chatDataRef conversation entry exists for the (potentially new) conversationId.
|
|
2232
|
+
// Must be called AFTER the ID check above so it uses the correct ID.
|
|
2233
|
+
ensureConversationExists(flowType, conversationId, chatDataRef);
|
|
2234
|
+
chatDataRef.current[flowType].conversations[conversationId].messages = [
|
|
2235
|
+
...chatDataRef.current[flowType].conversations[conversationId].messages,
|
|
2213
2236
|
userChat,
|
|
2214
2237
|
loaderData,
|
|
2215
2238
|
];
|
|
2216
|
-
chatDataInfoRef.current[currentMode].conversations[
|
|
2217
|
-
...chatDataInfoRef.current[currentMode].conversations[
|
|
2239
|
+
chatDataInfoRef.current[currentMode].conversations[conversationId].messages = [
|
|
2240
|
+
...chatDataInfoRef.current[currentMode].conversations[conversationId].messages,
|
|
2218
2241
|
userChat,
|
|
2219
2242
|
];
|
|
2220
2243
|
setLoader(true);
|
|
@@ -2237,13 +2260,13 @@ const useChatFlow = (chatDataRef, setLoader, setFlowType, setScreenName, setUser
|
|
|
2237
2260
|
// );
|
|
2238
2261
|
getUpdatedChat = parseResponse({ ...queryResponse?.data?.data }, "questions");
|
|
2239
2262
|
}
|
|
2240
|
-
chatDataRef.current[flowType].conversations[
|
|
2241
|
-
...chatDataRef.current[flowType].conversations[
|
|
2263
|
+
chatDataRef.current[flowType].conversations[conversationId].messages = [
|
|
2264
|
+
...chatDataRef.current[flowType].conversations[conversationId].messages?.filter((data) => data?.userType !== "loader"),
|
|
2242
2265
|
getUpdatedChat,
|
|
2243
2266
|
];
|
|
2244
|
-
let chatDataMessages = chatDataInfoRef.current[currentMode].conversations[
|
|
2267
|
+
let chatDataMessages = chatDataInfoRef.current[currentMode].conversations[conversationId].messages;
|
|
2245
2268
|
chatDataMessages = [...chatDataMessages, getUpdatedChat];
|
|
2246
|
-
chatDataInfoRef.current[currentMode].conversations[
|
|
2269
|
+
chatDataInfoRef.current[currentMode].conversations[conversationId].messages = chatDataMessages;
|
|
2247
2270
|
// Trigger re-render by updating chatDataState
|
|
2248
2271
|
setChatDataState({ ...chatDataRef.current });
|
|
2249
2272
|
}
|
|
@@ -2262,7 +2285,7 @@ const useChatFlow = (chatDataRef, setLoader, setFlowType, setScreenName, setUser
|
|
|
2262
2285
|
};
|
|
2263
2286
|
}
|
|
2264
2287
|
let utitlityObject = {
|
|
2265
|
-
activeConversationId,
|
|
2288
|
+
activeConversationId: conversationId,
|
|
2266
2289
|
currentMode,
|
|
2267
2290
|
chatDataRef,
|
|
2268
2291
|
chatBodyRef,
|
|
@@ -2299,13 +2322,13 @@ const useChatFlow = (chatDataRef, setLoader, setFlowType, setScreenName, setUser
|
|
|
2299
2322
|
getUpdatedChat = parseResponse({ ...responseData, enableLikes: true }, "text");
|
|
2300
2323
|
}
|
|
2301
2324
|
}
|
|
2302
|
-
chatDataRef.current[currentMode].conversations[
|
|
2303
|
-
...chatDataRef.current[currentMode].conversations[
|
|
2325
|
+
chatDataRef.current[currentMode].conversations[conversationId].messages = [
|
|
2326
|
+
...chatDataRef.current[currentMode].conversations[conversationId].messages?.filter((data) => data?.userType !== "loader"),
|
|
2304
2327
|
getUpdatedChat,
|
|
2305
2328
|
];
|
|
2306
|
-
let chatDataMessages = chatDataInfoRef.current[currentMode].conversations[
|
|
2329
|
+
let chatDataMessages = chatDataInfoRef.current[currentMode].conversations[conversationId].messages;
|
|
2307
2330
|
chatDataMessages = [...chatDataMessages, getUpdatedChat];
|
|
2308
|
-
chatDataInfoRef.current[currentMode].conversations[
|
|
2331
|
+
chatDataInfoRef.current[currentMode].conversations[conversationId].messages = chatDataMessages;
|
|
2309
2332
|
}
|
|
2310
2333
|
setChatDataState({ ...chatDataRef.current });
|
|
2311
2334
|
setLoader(false);
|
|
@@ -2322,13 +2345,13 @@ const useChatFlow = (chatDataRef, setLoader, setFlowType, setScreenName, setUser
|
|
|
2322
2345
|
noShowHeaderTitle: true,
|
|
2323
2346
|
bodyType: "text",
|
|
2324
2347
|
};
|
|
2325
|
-
chatDataRef.current[currentMode].conversations[
|
|
2326
|
-
...chatDataRef.current[currentMode].conversations[
|
|
2348
|
+
chatDataRef.current[currentMode].conversations[conversationId].messages = [
|
|
2349
|
+
...chatDataRef.current[currentMode].conversations[conversationId].messages?.filter((data) => data.userType !== "loader"),
|
|
2327
2350
|
failResponseText,
|
|
2328
2351
|
];
|
|
2329
|
-
let chatDataMessages = chatDataInfoRef.current[currentMode].conversations[
|
|
2352
|
+
let chatDataMessages = chatDataInfoRef.current[currentMode].conversations[conversationId].messages;
|
|
2330
2353
|
chatDataMessages = [...chatDataMessages, failResponseText];
|
|
2331
|
-
chatDataInfoRef.current[currentMode].conversations[
|
|
2354
|
+
chatDataInfoRef.current[currentMode].conversations[conversationId].messages = chatDataMessages;
|
|
2332
2355
|
// Trigger re-render by updating chatDataState
|
|
2333
2356
|
setChatDataState({ ...chatDataRef.current });
|
|
2334
2357
|
setLoader(false);
|
|
@@ -2517,7 +2540,7 @@ const useChatSession = (chatDataRef, setFlowType, setScreenName, setUserInput, s
|
|
|
2517
2540
|
let chatDataInfo = lodash.cloneDeep(chatDataRef.current);
|
|
2518
2541
|
delete chatDataInfo.agent;
|
|
2519
2542
|
for (const property in chatDataInfo) {
|
|
2520
|
-
if (lodash.isEmpty(chatDataRef.current[property].conversations)) {
|
|
2543
|
+
if (lodash.isEmpty(chatDataRef.current[property].conversations) || !chatDataRef.current[property].conversations[activeConversationId]) {
|
|
2521
2544
|
ensureConversationExists(property, activeConversationId, chatDataRef);
|
|
2522
2545
|
}
|
|
2523
2546
|
}
|
|
@@ -3972,8 +3995,12 @@ const useChatState = () => {
|
|
|
3972
3995
|
});
|
|
3973
3996
|
const chatDataInfoRef = React.useRef({
|
|
3974
3997
|
insights: {},
|
|
3975
|
-
navigation: {
|
|
3976
|
-
|
|
3998
|
+
navigation: {
|
|
3999
|
+
conversations: {},
|
|
4000
|
+
},
|
|
4001
|
+
agent: {
|
|
4002
|
+
conversations: {},
|
|
4003
|
+
}
|
|
3977
4004
|
});
|
|
3978
4005
|
const chatBodyRef = React.useRef({});
|
|
3979
4006
|
const isDraggingRef = React.useRef(null);
|
|
@@ -4556,7 +4583,7 @@ const Rectangle = ({ type, icon, title, description, onClick, hoverable }) => {
|
|
|
4556
4583
|
return (jsxRuntime.jsx("div", { className: `${classes.rectangle} ${classes[type]} ${hoverable ? classes.rectangleHoverable : ''}`, onClick: onClick, title: isTruncated ? title : null, children: jsxRuntime.jsxs("div", { className: classes.textContainer, children: [jsxRuntime.jsx(material.Typography, { className: classes.title, ref: titleRef, children: title }), jsxRuntime.jsx(material.Typography, { className: classes.description, children: description })] }) }));
|
|
4557
4584
|
};
|
|
4558
4585
|
const ChatPlaceholder = (props) => {
|
|
4559
|
-
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, fieldNumber, setFieldNumber, setAdditionalArgs, questions, displayQuestions } = props;
|
|
4586
|
+
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, fieldNumber, setFieldNumber, setAdditionalArgs, questions, displayQuestions, setActiveConversationId } = props;
|
|
4560
4587
|
const classes = useStyles$5();
|
|
4561
4588
|
globalStyles();
|
|
4562
4589
|
const [cardList, setCardList] = React.useState([]);
|
|
@@ -4587,6 +4614,7 @@ const ChatPlaceholder = (props) => {
|
|
|
4587
4614
|
fieldNumber,
|
|
4588
4615
|
setFieldNumber,
|
|
4589
4616
|
setAdditionalArgs,
|
|
4617
|
+
setActiveConversationId
|
|
4590
4618
|
});
|
|
4591
4619
|
const getBaseUrl = async () => {
|
|
4592
4620
|
try {
|
|
@@ -5985,7 +6013,7 @@ const formatThinkingTime = (seconds) => {
|
|
|
5985
6013
|
* @param {Function} botData.utilityObject.setChatDataState - Function to update chat data state
|
|
5986
6014
|
*/
|
|
5987
6015
|
const StreamedContent = ({ botData }) => {
|
|
5988
|
-
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;
|
|
6016
|
+
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 || {};
|
|
5989
6017
|
const classes = useStyles$3();
|
|
5990
6018
|
useStyles$6();
|
|
5991
6019
|
const dispatch = reactRedux.useDispatch();
|
|
@@ -6359,8 +6387,8 @@ const StreamedContent = ({ botData }) => {
|
|
|
6359
6387
|
chatDataRef.current[currentMode] = [
|
|
6360
6388
|
...chatDataRef.current[currentMode].slice(0, -1),
|
|
6361
6389
|
];
|
|
6362
|
-
chatDataInfoRef.current[currentMode].conversations[
|
|
6363
|
-
...chatDataInfoRef.current[currentMode].conversations[
|
|
6390
|
+
chatDataInfoRef.current[currentMode].conversations[activeConversationId].messages = [
|
|
6391
|
+
...chatDataInfoRef.current[currentMode].conversations[activeConversationId].messages.slice(0, -1),
|
|
6364
6392
|
];
|
|
6365
6393
|
botData.utilityObject.setInitValue(messageToStoreRef.current.initValue);
|
|
6366
6394
|
botData.utilityObject.setSessionId(messageToStoreRef.current.sessionId);
|
|
@@ -6426,7 +6454,7 @@ const StreamedContent = ({ botData }) => {
|
|
|
6426
6454
|
currentTabValue: "agent_response",
|
|
6427
6455
|
questions: lodash.cloneDeep(questionsRef.current),
|
|
6428
6456
|
questionsStepsMap: lodash.cloneDeep(questionsStepsMapRef.current),
|
|
6429
|
-
});
|
|
6457
|
+
}, activeConversationId);
|
|
6430
6458
|
// [
|
|
6431
6459
|
// {
|
|
6432
6460
|
// header: "Finding relevant information",
|
|
@@ -6476,13 +6504,15 @@ const StreamedContent = ({ botData }) => {
|
|
|
6476
6504
|
// // enableLikes: true
|
|
6477
6505
|
// },
|
|
6478
6506
|
];
|
|
6479
|
-
chatDataInfoRef.current[currentMode]
|
|
6480
|
-
|
|
6481
|
-
|
|
6482
|
-
|
|
6483
|
-
|
|
6484
|
-
|
|
6485
|
-
|
|
6507
|
+
if (chatDataInfoRef.current[currentMode]?.conversations?.[activeConversationId]) {
|
|
6508
|
+
chatDataInfoRef.current[currentMode].conversations[activeConversationId].messages = [
|
|
6509
|
+
...chatDataInfoRef.current[currentMode].conversations?.[activeConversationId]?.messages?.slice(0, -1),
|
|
6510
|
+
// {
|
|
6511
|
+
// ...parsedResponse,
|
|
6512
|
+
// // enableLikes: true
|
|
6513
|
+
// },
|
|
6514
|
+
];
|
|
6515
|
+
}
|
|
6486
6516
|
let finalData = isArray(messageToStoreRef?.current?.appendedData)
|
|
6487
6517
|
? messageToStoreRef?.current?.appendedData
|
|
6488
6518
|
: isEmpty(messageToStoreRef?.current?.appendedData)
|
|
@@ -6506,7 +6536,7 @@ const StreamedContent = ({ botData }) => {
|
|
|
6506
6536
|
currentTabValue: "agent_response",
|
|
6507
6537
|
questions: lodash.cloneDeep(questionsRef.current),
|
|
6508
6538
|
questionsStepsMap: lodash.cloneDeep(questionsStepsMapRef.current),
|
|
6509
|
-
});
|
|
6539
|
+
}, activeConversationId);
|
|
6510
6540
|
}
|
|
6511
6541
|
// Clean up module-level Map entry - stream is fully processed
|
|
6512
6542
|
streamStateMap.delete(streamKey);
|
|
@@ -6515,7 +6545,7 @@ const StreamedContent = ({ botData }) => {
|
|
|
6515
6545
|
setChatDataState({ ...chatDataRef.current });
|
|
6516
6546
|
}, 1000);
|
|
6517
6547
|
}
|
|
6518
|
-
}, [isStreamingDone, thinkingTime]);
|
|
6548
|
+
}, [isStreamingDone, thinkingTime, activeConversationId]);
|
|
6519
6549
|
React.useEffect(() => {
|
|
6520
6550
|
if (currentMode === "agent") {
|
|
6521
6551
|
if (sourceRef.current && isStreaming) {
|
|
@@ -8521,7 +8551,7 @@ const useMentionState = () => {
|
|
|
8521
8551
|
};
|
|
8522
8552
|
|
|
8523
8553
|
const ChatbotInput = (props) => {
|
|
8524
|
-
const { newChatScreen, inputValue, setInputValue, isStopIcon, handleMicClick, handleRefresh, onSendIconClick, onStopIconClick, currentMode, filterOptions, } = props;
|
|
8554
|
+
const { newChatScreen, inputValue, setInputValue, isStopIcon, handleMicClick, handleRefresh, onSendIconClick, onStopIconClick, currentMode, filterOptions, onSaveClick, } = props;
|
|
8525
8555
|
const editorRef = React.useRef(null);
|
|
8526
8556
|
const selectRef = React.useRef(null);
|
|
8527
8557
|
const dateRangePickerRef = React.useRef(null);
|
|
@@ -9831,7 +9861,9 @@ const ChatbotInput = (props) => {
|
|
|
9831
9861
|
// disableType="disableOnlyPast"
|
|
9832
9862
|
, {
|
|
9833
9863
|
// disableType="disableOnlyPast"
|
|
9834
|
-
startDate: dateRangeStartDate, endDate: dateRangeEndDate, focusedInput: dateRangeFocusedInput, onDatesChange: handleDateRangeChange, onFocusChange: setDateRangeFocusedInput }) })), jsxRuntime.jsxs("div", { className: `chat-actions ${isFixed ? "fixed" : ""}`, children: [handleRefresh && (jsxRuntime.jsx(impactUiV3.Button, { icon: jsxRuntime.jsx(SvgChatBotRefreshIcon, {}), iconPlacement: "left", size: "large", type: "default", variant: "url", onClick: handleRefresh })), handleMicClick && (jsxRuntime.jsx(impactUiV3.Button, { icon: jsxRuntime.jsx(SvgChatBotMicIcon, {}), iconPlacement: "left", size: "large", type: "default", variant: "tertiary", onClick: handleMicClick })), jsxRuntime.jsx(impactUiV3.
|
|
9864
|
+
startDate: dateRangeStartDate, endDate: dateRangeEndDate, focusedInput: dateRangeFocusedInput, onDatesChange: handleDateRangeChange, onFocusChange: setDateRangeFocusedInput }) })), jsxRuntime.jsxs("div", { className: `chat-actions ${isFixed ? "fixed" : ""}`, children: [handleRefresh && (jsxRuntime.jsx(impactUiV3.Button, { icon: jsxRuntime.jsx(SvgChatBotRefreshIcon, {}), iconPlacement: "left", size: "large", type: "default", variant: "url", onClick: handleRefresh })), handleMicClick && (jsxRuntime.jsx(impactUiV3.Button, { icon: jsxRuntime.jsx(SvgChatBotMicIcon, {}), iconPlacement: "left", size: "large", type: "default", variant: "tertiary", onClick: handleMicClick })), onSaveClick && (jsxRuntime.jsx(impactUiV3.Tooltip, { title: "Save Chat", children: jsxRuntime.jsx(impactUiV3.Button, { icon: jsxRuntime.jsx(SaveOutlinedIcon, {}), iconPlacement: "left", size: "large", type: "default", variant: "tertiary", onClick: onSaveClick, id: "chat-input-save-button" }) })), jsxRuntime.jsx(impactUiV3.Button, { icon: !isStopIcon ? jsxRuntime.jsx(SvgChatBotSendIcon, {}) : jsxRuntime.jsx(SvgChatbotStopIcon, {}), iconPlacement: "left", size: "large", type: "default", variant: "primary", onClick: () => {
|
|
9865
|
+
!isStopIcon ? handleSendMessage() : onStopIconClick();
|
|
9866
|
+
}, id: "chat-input-send-button", className: isStopIcon ? "stop-icon-button" : "" })] })] }) }));
|
|
9835
9867
|
};
|
|
9836
9868
|
|
|
9837
9869
|
let chatbotFilterCustomConfig = {
|
|
@@ -9908,6 +9940,519 @@ let chatbotFilterCustomConfig = {
|
|
|
9908
9940
|
sub_offset: null,
|
|
9909
9941
|
download_rows: null,
|
|
9910
9942
|
};
|
|
9943
|
+
let singleConversationNewData = [
|
|
9944
|
+
{
|
|
9945
|
+
userType: "user",
|
|
9946
|
+
chatType: "text",
|
|
9947
|
+
data: "List the products which are about to change status in next 10 days",
|
|
9948
|
+
},
|
|
9949
|
+
{
|
|
9950
|
+
userType: "bot",
|
|
9951
|
+
chatType: "thinking",
|
|
9952
|
+
data: "I will fetch all product status records with effective date ranges that begin or end within the next 10 days. This will provide the raw data needed to identify which products are about to change their active/inactive status soon. Downstream nodes will filter and compute which products have a status transition in the specified window, ensuring the user receives a list of products with upcoming status changes.I will fetch all product status records with effective date ranges that begin or end within the next 10 days. This will provide the raw data needed to identify which products are about to change their active/inactive status soon. Downstream nodes will filter and compute which products have a status transition in the specified window, ensuring the user receives a list of products with upcoming status changes.",
|
|
9953
|
+
},
|
|
9954
|
+
{
|
|
9955
|
+
userType: "bot",
|
|
9956
|
+
chatType: "steps",
|
|
9957
|
+
data: [
|
|
9958
|
+
{
|
|
9959
|
+
header: "Assessing user query",
|
|
9960
|
+
step_status: "completed",
|
|
9961
|
+
sub_header: "Query is within scope and determined as New query",
|
|
9962
|
+
current_intent: "List the products which are about to change status in next 10 days"
|
|
9963
|
+
},
|
|
9964
|
+
{
|
|
9965
|
+
header: "Creating Plan of Action",
|
|
9966
|
+
step_status: "completed",
|
|
9967
|
+
sub_header: "Alan is working to determine the best approach to answer user query",
|
|
9968
|
+
current_intent: "List the products which are about to change status in next 10 days"
|
|
9969
|
+
},
|
|
9970
|
+
{
|
|
9971
|
+
header: "Executing Step",
|
|
9972
|
+
step_status: "completed",
|
|
9973
|
+
sub_header: "Executing Step 1/1",
|
|
9974
|
+
current_intent: "List the products which are about to change status in next 10 days"
|
|
9975
|
+
},
|
|
9976
|
+
]
|
|
9977
|
+
},
|
|
9978
|
+
{
|
|
9979
|
+
userType: "bot",
|
|
9980
|
+
chatType: "agent",
|
|
9981
|
+
data: [
|
|
9982
|
+
{ "type": "select", "data": { "header": "Select", "inputPosition": "inline", "labelOrientation": "top", "label": "L0 Name", "param_name": "l0_name", "options": [{ "label": "Coach", "value": "Coach" }, { "label": "KateSpade", "value": "KateSpade" }], "isRequired": true, "isDisabled": false, "isMulti": true } }, { "type": "select", "data": { "header": "Select", "inputPosition": "inline", "labelOrientation": "top", "label": "L1 Name", "param_name": "l1_name", "options": [{ "label": "Outlet-Store", "value": "Outlet-Store" }, { "label": "Retail-Store", "value": "Retail-Store" }], "isRequired": true, "isDisabled": false, "isMulti": true } }, { "type": "table", "data": { "display_name": "Results", "unique_id": "", "row_data": [{ "Style Color ID": "CDM80 B4__ia_char_03M2-Retail-Store", "Style Description": "DSNY GLOV SWINGER", "stockout_store_count": 346, "max_dc_oh_it_oo": 284.0, "lw_sales_units": 6 }, { "Style Color ID": "CDN03 B4PF7-Retail-Store", "Style Description": "DSNY GLOV SWINGER", "stockout_store_count": 346, "max_dc_oh_it_oo": 274.0, "lw_sales_units": 5 }, { "Style Color ID": "CT255 IMWQJ-Retail-Store", "Style Description": "LTH STP JAMIE CMR", "stockout_store_count": 346, "max_dc_oh_it_oo": 13.0, "lw_sales_units": 2 }, { "Style Color ID": "CZ186 IMY4C-Retail-Store", "Style Description": "SIG JAMIE CMR", "stockout_store_count": 346, "max_dc_oh_it_oo": 6.0, "lw_sales_units": 1 }, { "Style Color ID": "CCZ17 IMA47-Retail-Store", "Style Description": "CHRRY PT RWN BKT", "stockout_store_count": 346, "max_dc_oh_it_oo": 4.0, "lw_sales_units": 1 }], "table_config": [{ "column_header": "Style Color Id", "field": "Style Color ID", "is_searchable": true, "type": "str" }, { "column_header": "Style Description", "field": "Style Description", "is_searchable": true }, { "column_header": "Stockout Store Count", "field": "stockout_store_count", "is_searchable": true }, { "column_header": "Max Dc Oh It Oo", "field": "max_dc_oh_it_oo", "is_searchable": true }, { "column_header": "Lw Sales Units", "field": "lw_sales_units", "is_searchable": true }] } }
|
|
9983
|
+
]
|
|
9984
|
+
}
|
|
9985
|
+
];
|
|
9986
|
+
|
|
9987
|
+
const fetchConversations = async (currentMode) => {
|
|
9988
|
+
try {
|
|
9989
|
+
// Will be replaced with actual API call
|
|
9990
|
+
return axiosInstance({
|
|
9991
|
+
url: `core/chatbot/conversation/${currentMode}`,
|
|
9992
|
+
method: "GET"
|
|
9993
|
+
});
|
|
9994
|
+
// return {
|
|
9995
|
+
// status: true,
|
|
9996
|
+
// data: {
|
|
9997
|
+
// data: [
|
|
9998
|
+
// {
|
|
9999
|
+
// conversation_id: 10,
|
|
10000
|
+
// module_name: moduleType.toUpperCase(),
|
|
10001
|
+
// flow_type: moduleType.toUpperCase(),
|
|
10002
|
+
// name: "test chatbot's name",
|
|
10003
|
+
// created_at: new Date().toISOString(),
|
|
10004
|
+
// updated_at: new Date().toISOString(),
|
|
10005
|
+
// }
|
|
10006
|
+
// ]
|
|
10007
|
+
// }
|
|
10008
|
+
// };
|
|
10009
|
+
}
|
|
10010
|
+
catch (error) {
|
|
10011
|
+
console.error("fetchConversations error", error);
|
|
10012
|
+
return null;
|
|
10013
|
+
}
|
|
10014
|
+
};
|
|
10015
|
+
const createConversation = async (payload) => {
|
|
10016
|
+
try {
|
|
10017
|
+
return axiosInstance({
|
|
10018
|
+
url: `core/chatbot/conversation`,
|
|
10019
|
+
method: "POST",
|
|
10020
|
+
data: payload
|
|
10021
|
+
});
|
|
10022
|
+
}
|
|
10023
|
+
catch (error) {
|
|
10024
|
+
console.error("createConversation error", error);
|
|
10025
|
+
return null;
|
|
10026
|
+
}
|
|
10027
|
+
};
|
|
10028
|
+
const updateConversation = async (conversationId, payload) => {
|
|
10029
|
+
try {
|
|
10030
|
+
return axiosInstance({
|
|
10031
|
+
url: `core/chatbot/conversation/update`,
|
|
10032
|
+
method: "POST",
|
|
10033
|
+
data: payload
|
|
10034
|
+
});
|
|
10035
|
+
}
|
|
10036
|
+
catch (error) {
|
|
10037
|
+
console.error("updateConversation error", error);
|
|
10038
|
+
return null;
|
|
10039
|
+
}
|
|
10040
|
+
};
|
|
10041
|
+
const deleteConversation = async (conversationId) => {
|
|
10042
|
+
try {
|
|
10043
|
+
return axiosInstance({
|
|
10044
|
+
url: `core/chatbot/conversation/${conversationId}`,
|
|
10045
|
+
method: "DELETE"
|
|
10046
|
+
});
|
|
10047
|
+
}
|
|
10048
|
+
catch (error) {
|
|
10049
|
+
console.error("deleteConversation error", error);
|
|
10050
|
+
return null;
|
|
10051
|
+
}
|
|
10052
|
+
};
|
|
10053
|
+
const saveChat = async (payload) => {
|
|
10054
|
+
try {
|
|
10055
|
+
return axiosInstance({
|
|
10056
|
+
url: `core/chatbot/conversation`,
|
|
10057
|
+
method: "POST",
|
|
10058
|
+
data: payload
|
|
10059
|
+
});
|
|
10060
|
+
}
|
|
10061
|
+
catch (error) {
|
|
10062
|
+
console.error("saveChat error", error);
|
|
10063
|
+
return null;
|
|
10064
|
+
}
|
|
10065
|
+
};
|
|
10066
|
+
|
|
10067
|
+
const useConversationManagement = (chatDataRef, currentMode, activeConversationId, setActiveConversationId, setChatDataState, selectedModule, setSelectedModule, isModuleChanged, setIsModuleChanged, setActiveChatId = () => { }, saveCurrentChanges = () => { }, chatDataInfoRef = null, setHistoryPanelData = (_data) => { }, processResponse = null) => {
|
|
10068
|
+
const [loading, setLoading] = React.useState(false);
|
|
10069
|
+
const [error, setError] = React.useState(null);
|
|
10070
|
+
const fetchConversations$1 = React.useCallback(async (activeChatId = null, mode = null) => {
|
|
10071
|
+
try {
|
|
10072
|
+
setLoading(true);
|
|
10073
|
+
const effectiveMode = mode || currentMode;
|
|
10074
|
+
const response = await fetchConversations(effectiveMode);
|
|
10075
|
+
// const response = {
|
|
10076
|
+
// status: true,
|
|
10077
|
+
// data: {
|
|
10078
|
+
// data: [
|
|
10079
|
+
// {
|
|
10080
|
+
// conversation_id: 1,
|
|
10081
|
+
// name: "Getting Started Guide",
|
|
10082
|
+
// created_at: new Date().toISOString(),
|
|
10083
|
+
// updated_at: new Date().toISOString(),
|
|
10084
|
+
// },
|
|
10085
|
+
// {
|
|
10086
|
+
// conversation_id: 2,
|
|
10087
|
+
// name: "Product Features Discussion",
|
|
10088
|
+
// created_at: new Date(Date.now() - 86400000).toISOString(), // 1 day ago
|
|
10089
|
+
// updated_at: new Date(Date.now() - 86400000).toISOString(),
|
|
10090
|
+
// },
|
|
10091
|
+
// {
|
|
10092
|
+
// conversation_id: 3,
|
|
10093
|
+
// name: "Troubleshooting Help",
|
|
10094
|
+
// created_at: new Date(Date.now() - 172800000).toISOString(), // 2 days ago
|
|
10095
|
+
// updated_at: new Date(Date.now() - 172800000).toISOString(),
|
|
10096
|
+
// },
|
|
10097
|
+
// {
|
|
10098
|
+
// conversation_id: 4,
|
|
10099
|
+
// name: "Project Discussion",
|
|
10100
|
+
// created_at: new Date(Date.now() - 948220200000).toISOString(), // 2 days ago
|
|
10101
|
+
// updated_at: new Date(Date.now() - 948220200000).toISOString(),
|
|
10102
|
+
// },
|
|
10103
|
+
// ],
|
|
10104
|
+
// },
|
|
10105
|
+
// };
|
|
10106
|
+
if (response?.data?.status) {
|
|
10107
|
+
const conversationsList = response.data.data.data;
|
|
10108
|
+
chatDataRef.current[effectiveMode].conversationsList = conversationsList;
|
|
10109
|
+
// Process conversations from each time group
|
|
10110
|
+
conversationsList.forEach(group => {
|
|
10111
|
+
group.conversation_list.forEach(conversation => {
|
|
10112
|
+
// chatDataRef.current[currentMode].conversations[conversation.conversation_id] = {
|
|
10113
|
+
// id: conversation.conversation_id,
|
|
10114
|
+
// name: conversation.name,
|
|
10115
|
+
// idGenerated: true,
|
|
10116
|
+
// timestamp: conversation.created_at || new Date().toISOString(),
|
|
10117
|
+
// messages: []
|
|
10118
|
+
// };
|
|
10119
|
+
if (chatDataInfoRef?.current[effectiveMode]?.conversations?.[conversation.conversation_id]?.messages) {
|
|
10120
|
+
chatDataInfoRef.current[effectiveMode].conversations[conversation.conversation_id] = {
|
|
10121
|
+
id: conversation.conversation_id,
|
|
10122
|
+
name: conversation.name,
|
|
10123
|
+
idGenerated: true,
|
|
10124
|
+
timestamp: conversation.created_at || new Date().toISOString(),
|
|
10125
|
+
messages: chatDataInfoRef.current[effectiveMode].conversations[conversation.conversation_id].messages
|
|
10126
|
+
};
|
|
10127
|
+
}
|
|
10128
|
+
});
|
|
10129
|
+
});
|
|
10130
|
+
setHistoryPanelData(conversationsList);
|
|
10131
|
+
setChatDataState({ ...chatDataRef.current });
|
|
10132
|
+
if (activeChatId) {
|
|
10133
|
+
setActiveChatId(activeChatId);
|
|
10134
|
+
}
|
|
10135
|
+
// Set first conversation as active if none selected
|
|
10136
|
+
// if (!activeConversationId && Object.keys(conversations).length > 0) {
|
|
10137
|
+
// setActiveConversationId(Object.keys(conversations)[0]);
|
|
10138
|
+
// }
|
|
10139
|
+
}
|
|
10140
|
+
}
|
|
10141
|
+
catch (err) {
|
|
10142
|
+
setError(err.message);
|
|
10143
|
+
}
|
|
10144
|
+
finally {
|
|
10145
|
+
setLoading(false);
|
|
10146
|
+
}
|
|
10147
|
+
}, [currentMode]);
|
|
10148
|
+
const fetchConversationChats = React.useCallback(async (conversationId, mode = null) => {
|
|
10149
|
+
const effectiveMode = mode || currentMode;
|
|
10150
|
+
try {
|
|
10151
|
+
setLoading(true);
|
|
10152
|
+
// --- Use hardcoded test data for now ---
|
|
10153
|
+
const savedData = singleConversationNewData;
|
|
10154
|
+
// Generate a conversation ID for the saved chat
|
|
10155
|
+
const savedConvId = conversationId || generateConversationId();
|
|
10156
|
+
// Ensure a conversation slot exists in chatDataInfoRef
|
|
10157
|
+
if (chatDataInfoRef) {
|
|
10158
|
+
if (!chatDataInfoRef.current[effectiveMode]?.conversations) {
|
|
10159
|
+
chatDataInfoRef.current[effectiveMode] = { conversations: {} };
|
|
10160
|
+
}
|
|
10161
|
+
chatDataInfoRef.current[effectiveMode].conversations[savedConvId] =
|
|
10162
|
+
generateConversationObject(savedConvId);
|
|
10163
|
+
}
|
|
10164
|
+
setActiveConversationId(savedConvId);
|
|
10165
|
+
// Build combined bot entries from the saved data
|
|
10166
|
+
// Collect thinking, steps, and agent response into a single combined message
|
|
10167
|
+
let thinkingResponse = {};
|
|
10168
|
+
let steps = [];
|
|
10169
|
+
const agentDataItems = [];
|
|
10170
|
+
let userMessage = null;
|
|
10171
|
+
savedData.forEach((item) => {
|
|
10172
|
+
if (item.userType === "user") {
|
|
10173
|
+
userMessage = {
|
|
10174
|
+
timeStamp: moment().format("DD-MM-YYYY HH:mm:ss"),
|
|
10175
|
+
userType: "user",
|
|
10176
|
+
bodyText: item.data,
|
|
10177
|
+
bodyType: "text",
|
|
10178
|
+
};
|
|
10179
|
+
}
|
|
10180
|
+
else if (item.chatType === "thinking") {
|
|
10181
|
+
thinkingResponse = {
|
|
10182
|
+
thinkingStream: item.data,
|
|
10183
|
+
thinkingContent: item.data,
|
|
10184
|
+
thinkingTime: 1,
|
|
10185
|
+
thinkingHeading: "Thinking Completed",
|
|
10186
|
+
};
|
|
10187
|
+
}
|
|
10188
|
+
else if (item.chatType === "steps") {
|
|
10189
|
+
steps = item.data;
|
|
10190
|
+
}
|
|
10191
|
+
else if (item.chatType === "agent") {
|
|
10192
|
+
// Agent response items (widgets, selects, etc.)
|
|
10193
|
+
if (Array.isArray(item.data)) {
|
|
10194
|
+
agentDataItems.push(...item.data);
|
|
10195
|
+
}
|
|
10196
|
+
else {
|
|
10197
|
+
agentDataItems.push(item.data);
|
|
10198
|
+
}
|
|
10199
|
+
}
|
|
10200
|
+
});
|
|
10201
|
+
// Add user message to conversation
|
|
10202
|
+
if (userMessage && chatDataInfoRef) {
|
|
10203
|
+
chatDataInfoRef.current[effectiveMode].conversations[savedConvId].messages.push(userMessage);
|
|
10204
|
+
chatDataRef.current[effectiveMode] = [
|
|
10205
|
+
...(chatDataRef.current[effectiveMode] || []),
|
|
10206
|
+
userMessage,
|
|
10207
|
+
];
|
|
10208
|
+
}
|
|
10209
|
+
// Build the response in the shape processResponse expects:
|
|
10210
|
+
// response.data.data.data = array of items
|
|
10211
|
+
const textItem = {
|
|
10212
|
+
type: "text",
|
|
10213
|
+
response: "",
|
|
10214
|
+
response_heading: "",
|
|
10215
|
+
thinkingResponse,
|
|
10216
|
+
};
|
|
10217
|
+
const responseData = [textItem, ...agentDataItems];
|
|
10218
|
+
const fakeResponse = {
|
|
10219
|
+
data: {
|
|
10220
|
+
data: {
|
|
10221
|
+
data: responseData,
|
|
10222
|
+
session_id: "",
|
|
10223
|
+
},
|
|
10224
|
+
},
|
|
10225
|
+
};
|
|
10226
|
+
// Call processResponse with steps/tabs context
|
|
10227
|
+
if (processResponse) {
|
|
10228
|
+
await processResponse(fakeResponse, {}, effectiveMode, null, {
|
|
10229
|
+
isTabEnabled: true,
|
|
10230
|
+
steps,
|
|
10231
|
+
currentTabValue: "agent_response",
|
|
10232
|
+
questions: [],
|
|
10233
|
+
questionsStepsMap: {},
|
|
10234
|
+
}, savedConvId);
|
|
10235
|
+
}
|
|
10236
|
+
setChatDataState({ ...chatDataRef.current });
|
|
10237
|
+
}
|
|
10238
|
+
catch (err) {
|
|
10239
|
+
setError(err.message);
|
|
10240
|
+
console.error("fetchConversationChats error:", err);
|
|
10241
|
+
}
|
|
10242
|
+
finally {
|
|
10243
|
+
setLoading(false);
|
|
10244
|
+
}
|
|
10245
|
+
}, [currentMode, processResponse]);
|
|
10246
|
+
const createNewConversation = React.useCallback(async (name) => {
|
|
10247
|
+
try {
|
|
10248
|
+
setLoading(true);
|
|
10249
|
+
const payload = {
|
|
10250
|
+
module_name: currentMode.toUpperCase(),
|
|
10251
|
+
flow_type: currentMode,
|
|
10252
|
+
name: name,
|
|
10253
|
+
application_code: 1,
|
|
10254
|
+
user_id: 251, // This should come from your auth context
|
|
10255
|
+
};
|
|
10256
|
+
const response = await createConversation(payload);
|
|
10257
|
+
if (response.status) {
|
|
10258
|
+
await fetchConversations$1();
|
|
10259
|
+
}
|
|
10260
|
+
}
|
|
10261
|
+
catch (err) {
|
|
10262
|
+
setError(err.message);
|
|
10263
|
+
}
|
|
10264
|
+
finally {
|
|
10265
|
+
setLoading(false);
|
|
10266
|
+
}
|
|
10267
|
+
}, [currentMode]);
|
|
10268
|
+
const renameConversation = React.useCallback(async (conversationId, newName, mode = null) => {
|
|
10269
|
+
const effectiveMode = mode || currentMode;
|
|
10270
|
+
try {
|
|
10271
|
+
setLoading(true);
|
|
10272
|
+
const payload = {
|
|
10273
|
+
conversation_id: conversationId,
|
|
10274
|
+
name: newName
|
|
10275
|
+
};
|
|
10276
|
+
const response = await updateConversation(conversationId, payload);
|
|
10277
|
+
// const response = {
|
|
10278
|
+
// status: true,
|
|
10279
|
+
// message: "Conversation updated successfully"
|
|
10280
|
+
// };
|
|
10281
|
+
if (response?.data?.status) {
|
|
10282
|
+
// chatDataRef.current[currentMode].conversations[conversationId].name = newName;
|
|
10283
|
+
if (chatDataInfoRef) {
|
|
10284
|
+
chatDataInfoRef.current[effectiveMode].conversations[conversationId].name = newName;
|
|
10285
|
+
}
|
|
10286
|
+
setChatDataState({ ...chatDataRef.current });
|
|
10287
|
+
return true;
|
|
10288
|
+
}
|
|
10289
|
+
setLoading(false);
|
|
10290
|
+
}
|
|
10291
|
+
catch (err) {
|
|
10292
|
+
setError(err.message);
|
|
10293
|
+
console.error("renameConversation error:", err);
|
|
10294
|
+
setLoading(false);
|
|
10295
|
+
}
|
|
10296
|
+
finally {
|
|
10297
|
+
setLoading(false);
|
|
10298
|
+
}
|
|
10299
|
+
}, [currentMode]);
|
|
10300
|
+
const deleteConversation$1 = React.useCallback(async (conversationId, mode = null) => {
|
|
10301
|
+
const effectiveMode = mode || currentMode;
|
|
10302
|
+
try {
|
|
10303
|
+
setLoading(true);
|
|
10304
|
+
const response = await deleteConversation(conversationId);
|
|
10305
|
+
// const response = {
|
|
10306
|
+
// status: true,
|
|
10307
|
+
// message: "Conversation deleted successfully"
|
|
10308
|
+
// };
|
|
10309
|
+
if (response?.data?.status) {
|
|
10310
|
+
// delete chatDataRef.current[currentMode].conversations[conversationId];
|
|
10311
|
+
if (chatDataInfoRef) {
|
|
10312
|
+
delete chatDataInfoRef.current[effectiveMode].conversations[conversationId];
|
|
10313
|
+
}
|
|
10314
|
+
setChatDataState({ ...chatDataRef.current });
|
|
10315
|
+
// If deleted conversation was active, select another one
|
|
10316
|
+
if (activeConversationId === conversationId) {
|
|
10317
|
+
const remainingConversations = Object.keys(chatDataRef.current[effectiveMode].conversations);
|
|
10318
|
+
setActiveConversationId(remainingConversations[0] || null);
|
|
10319
|
+
}
|
|
10320
|
+
return true;
|
|
10321
|
+
}
|
|
10322
|
+
}
|
|
10323
|
+
catch (err) {
|
|
10324
|
+
setError(err.message);
|
|
10325
|
+
}
|
|
10326
|
+
finally {
|
|
10327
|
+
setLoading(false);
|
|
10328
|
+
}
|
|
10329
|
+
}, [currentMode, activeConversationId]);
|
|
10330
|
+
const saveCurrentChat = React.useCallback(async () => {
|
|
10331
|
+
try {
|
|
10332
|
+
setLoading(true);
|
|
10333
|
+
let userId = await getCurrentUserId();
|
|
10334
|
+
let isNewConversation = false;
|
|
10335
|
+
let newConversationName = "New Conversation";
|
|
10336
|
+
const dataRef = chatDataInfoRef || chatDataRef;
|
|
10337
|
+
// If no active conversation is selected, create a new one
|
|
10338
|
+
if (!activeConversationId) {
|
|
10339
|
+
isNewConversation = true;
|
|
10340
|
+
const conversationCount = Object.keys(dataRef.current[currentMode].conversations).length;
|
|
10341
|
+
const newConversationId = Date.now(); // Using timestamp as unique ID
|
|
10342
|
+
newConversationName = `Conversation ${conversationCount + 1}`;
|
|
10343
|
+
// Create new conversation object
|
|
10344
|
+
dataRef.current[currentMode].conversations[newConversationId] = {
|
|
10345
|
+
id: newConversationId,
|
|
10346
|
+
name: newConversationName,
|
|
10347
|
+
timestamp: new Date().toISOString(),
|
|
10348
|
+
messages: dataRef.current[currentMode].conversations[activeConversationId]?.messages || []
|
|
10349
|
+
};
|
|
10350
|
+
// Update active conversation
|
|
10351
|
+
setActiveConversationId(newConversationId);
|
|
10352
|
+
setChatDataState({ ...chatDataRef.current });
|
|
10353
|
+
}
|
|
10354
|
+
const currentChat = dataRef.current[currentMode].conversations[activeConversationId];
|
|
10355
|
+
let currentSelectedModuleData = JSON.parse(localStorage.getItem("currentSelectedModuleData"));
|
|
10356
|
+
let currentSelectedModuleForInsights = localStorage.getItem("smartBotScreenName");
|
|
10357
|
+
// if (currentMode === "insights") {
|
|
10358
|
+
// currentSelectedModuleData = JSON.parse(
|
|
10359
|
+
// localStorage.getItem("smartBotScreenName")
|
|
10360
|
+
// );
|
|
10361
|
+
// }
|
|
10362
|
+
const payload = {
|
|
10363
|
+
conversation_id: currentChat?.idGenerated ? currentChat.id : null,
|
|
10364
|
+
module_name: currentMode === "insights" ? currentSelectedModuleForInsights : currentSelectedModuleData ? currentSelectedModuleData[activeConversationId] : "",
|
|
10365
|
+
flow_type: currentMode,
|
|
10366
|
+
name: isNewConversation ? newConversationName : currentChat.name,
|
|
10367
|
+
is_module_changed: isModuleChanged,
|
|
10368
|
+
chats: currentChat.messages.map(msg => ({
|
|
10369
|
+
chat_id: null, // null for new chat messages
|
|
10370
|
+
chat_object: {
|
|
10371
|
+
bodyText: msg.bodyText,
|
|
10372
|
+
bodyType: msg.bodyType === "stream" ? "text" : (msg.bodyType || 'text'),
|
|
10373
|
+
userName: msg.userName,
|
|
10374
|
+
userType: msg.userType,
|
|
10375
|
+
timeStamp: msg.timeStamp,
|
|
10376
|
+
headerTitle: msg.headerTitle,
|
|
10377
|
+
thinkingResponse: msg.thinkingResponse ? {
|
|
10378
|
+
thinkingStream: msg.thinkingResponse.thinkingStream,
|
|
10379
|
+
thinkingTime: msg.thinkingResponse.thinkingTime,
|
|
10380
|
+
thinkingHeading: msg.thinkingResponse.thinkingHeading,
|
|
10381
|
+
} : undefined,
|
|
10382
|
+
}
|
|
10383
|
+
}))
|
|
10384
|
+
};
|
|
10385
|
+
setIsModuleChanged(false);
|
|
10386
|
+
const response = await saveChat(payload);
|
|
10387
|
+
let newConversationId = null;
|
|
10388
|
+
if (response && response?.data?.status) {
|
|
10389
|
+
// Extract the new conversation data from the response
|
|
10390
|
+
const newConversationData = response?.data?.data?.data[0];
|
|
10391
|
+
if (newConversationData) {
|
|
10392
|
+
// Get the new conversation ID
|
|
10393
|
+
newConversationId = newConversationData.conversation_id;
|
|
10394
|
+
// Preserve the existing rich in-memory messages (they contain
|
|
10395
|
+
// thinkingResponse, combined bodyText arrays, JSX, etc. that
|
|
10396
|
+
// the server response does not return). Only update metadata.
|
|
10397
|
+
const existingMessages = currentChat.messages;
|
|
10398
|
+
// Map server-assigned chat_ids back onto existing messages
|
|
10399
|
+
if (newConversationData.chats) {
|
|
10400
|
+
newConversationData.chats.forEach((chat, index) => {
|
|
10401
|
+
if (existingMessages[index]) {
|
|
10402
|
+
existingMessages[index].id = chat.chat_id;
|
|
10403
|
+
}
|
|
10404
|
+
});
|
|
10405
|
+
}
|
|
10406
|
+
// Update conversation with server metadata but keep existing messages
|
|
10407
|
+
dataRef.current[currentMode].conversations[newConversationId] = {
|
|
10408
|
+
id: newConversationId,
|
|
10409
|
+
name: newConversationData.name,
|
|
10410
|
+
idGenerated: true,
|
|
10411
|
+
timestamp: newConversationData.created_at,
|
|
10412
|
+
messages: existingMessages,
|
|
10413
|
+
};
|
|
10414
|
+
// Keep chatDataRef in sync as well. Many parts of the UI re-render
|
|
10415
|
+
// based on setChatDataState({...chatDataRef.current}). If we only
|
|
10416
|
+
// update chatDataInfoRef, the UI can temporarily see an empty chat
|
|
10417
|
+
// and clear the conversation.
|
|
10418
|
+
if (chatDataInfoRef) {
|
|
10419
|
+
chatDataInfoRef.current[currentMode].conversations[newConversationId] = {
|
|
10420
|
+
id: newConversationId,
|
|
10421
|
+
name: newConversationData.name,
|
|
10422
|
+
idGenerated: true,
|
|
10423
|
+
timestamp: newConversationData.created_at,
|
|
10424
|
+
messages: existingMessages,
|
|
10425
|
+
};
|
|
10426
|
+
}
|
|
10427
|
+
// Update active conversation ID to the server-provided one
|
|
10428
|
+
setActiveConversationId(newConversationId);
|
|
10429
|
+
// Update the chat data state
|
|
10430
|
+
setChatDataState({ ...chatDataInfoRef.current });
|
|
10431
|
+
// Refresh the conversation list to show the new conversation
|
|
10432
|
+
await fetchConversations$1(newConversationId, "agent");
|
|
10433
|
+
}
|
|
10434
|
+
}
|
|
10435
|
+
}
|
|
10436
|
+
catch (err) {
|
|
10437
|
+
setError(err.message);
|
|
10438
|
+
console.error("saveCurrentChat error:", err);
|
|
10439
|
+
return false;
|
|
10440
|
+
}
|
|
10441
|
+
finally {
|
|
10442
|
+
setLoading(false);
|
|
10443
|
+
}
|
|
10444
|
+
}, [currentMode, activeConversationId, isModuleChanged]);
|
|
10445
|
+
return {
|
|
10446
|
+
loading,
|
|
10447
|
+
error,
|
|
10448
|
+
fetchConversations: fetchConversations$1,
|
|
10449
|
+
fetchConversationChats,
|
|
10450
|
+
createNewConversation,
|
|
10451
|
+
renameConversation,
|
|
10452
|
+
deleteConversation: deleteConversation$1,
|
|
10453
|
+
saveCurrentChat
|
|
10454
|
+
};
|
|
10455
|
+
};
|
|
9911
10456
|
|
|
9912
10457
|
const SmartBot = (props) => {
|
|
9913
10458
|
const { userName, partialClose, setPartialClose, forceOpen, customBaseUrl = "", displayQuestions, questions = [] } = props;
|
|
@@ -9919,6 +10464,9 @@ const SmartBot = (props) => {
|
|
|
9919
10464
|
React.useState(false);
|
|
9920
10465
|
const [conversation, setConversation] = React.useState({});
|
|
9921
10466
|
const { chatbotContext, currentAgentChatId } = reactRedux.useSelector((state) => state.smartBotReducer);
|
|
10467
|
+
// Per-mode conversation ID tracking — prevents cross-mode contamination when
|
|
10468
|
+
// switching tabs while streams are pending.
|
|
10469
|
+
React.useRef({});
|
|
9922
10470
|
const activeTab = React.useRef({
|
|
9923
10471
|
activeTab: "dashboard",
|
|
9924
10472
|
});
|
|
@@ -9935,12 +10483,14 @@ const SmartBot = (props) => {
|
|
|
9935
10483
|
const [isLandingScreen, setIsLandingScreen] = React.useState(true);
|
|
9936
10484
|
const [showSuggestionBanner, setShowSuggestionBanner] = React.useState(true);
|
|
9937
10485
|
const [filterOptions, setFilterOptions] = React.useState([]);
|
|
9938
|
-
|
|
10486
|
+
React.useRef(0);
|
|
10487
|
+
const { setUserFlow, setUserScreenAndFlow, fetchUserResultsFromQuery, getCurrentDateTimeString, setLink, } = useChatFlow(chatDataRef, setLoader, setFlowType, setScreenName, setUserInput, setQuestionIndex, setCurrentAppLink, flowType, screenName, questionIndex, userInput, dateFormat, currentMode, activeConversationId, setIsModuleChanged, chatBodyRef, filterReducerState, dispatch, navigate, setShowChatPlaceholder, baseUrl, setChatDataState, setCurrentSessionId, customChatConfig, chatDataInfoRef, chatbotContext, setInitValue, setSessionId, thinkingContent, setThinkingContent, isThinking, setIsThinking, chatId, setChatId, isStop, setIsStop, functionsRef, functionsState, setFunctionsState, thinkingHeaderMessage, setThinkingHeaderMessage, uniqueChatId, initValue, sessionId, fieldNumber, setFieldNumber, additionalArgs, setActiveConversationId);
|
|
9939
10488
|
const { parseSavedFlow, saveCurrentChanges, endCurrentSession, clearChatSession, initiateNewChat, hasUnsavedChanges, } = useChatSession(chatDataRef, setFlowType, setScreenName, setUserInput, setTemplateData, chatDataScreenLinkRef, setShowModal, setMinimizedMode, setSelectedModule, setChatDataState, currentMode, setUserFlow, getCurrentDateTimeString, setCurrentAppLink, selectedModule, fetchUserResultsFromQuery, props.closeBot, activeConversationId, setActiveConversationId, setShowChatPlaceholder);
|
|
9940
10489
|
const { refreshAndUpdateUserManual, configureBotActions, displaySnackMessages, } = useBotConfiguration(setRefreshLoader, setEnableRefreshAction, dispatch);
|
|
9941
|
-
const { prepareDataAndSendToAgent } = useAgentFlow(dateFormat, chatDataRef, currentMode, setShowChatPlaceholder, setLoader, baseUrl, setCurrentSessionId, customChatConfig, chatDataInfoRef, {
|
|
10490
|
+
const { prepareDataAndSendToAgent, processResponse } = useAgentFlow(dateFormat, chatDataRef, currentMode, setShowChatPlaceholder, setLoader, baseUrl, setCurrentSessionId, customChatConfig, chatDataInfoRef, {
|
|
9942
10491
|
setChatDataState,
|
|
9943
10492
|
activeConversationId,
|
|
10493
|
+
setActiveConversationId,
|
|
9944
10494
|
chatBodyRef,
|
|
9945
10495
|
runStreaming: true,
|
|
9946
10496
|
chatbotContext,
|
|
@@ -10062,7 +10612,7 @@ const SmartBot = (props) => {
|
|
|
10062
10612
|
[isLike ? "like" : "dislike"]: key,
|
|
10063
10613
|
});
|
|
10064
10614
|
handleMessageLike(key, isLike, setLoadingState, displaySnackMessages, templateData, activeConversationId, answer, chatDataInfoRef.current, chatIndex, setChatDataState, baseUrl, sessionId);
|
|
10065
|
-
}, 5000, { trailing: false }), [loadingState, templateData, displaySnackMessages, sessionId, baseUrl]);
|
|
10615
|
+
}, 5000, { trailing: false }), [loadingState, templateData, displaySnackMessages, activeConversationId, sessionId, baseUrl]);
|
|
10066
10616
|
React.useEffect(() => {
|
|
10067
10617
|
handleUploadAccess();
|
|
10068
10618
|
}, []);
|
|
@@ -10072,21 +10622,12 @@ const SmartBot = (props) => {
|
|
|
10072
10622
|
React.useEffect(() => {
|
|
10073
10623
|
fetchCustomBotConfigurations();
|
|
10074
10624
|
}, [baseUrl]);
|
|
10075
|
-
// Sync showModal state with props.showModal OR props.invokeBot (backward compatibility)
|
|
10076
|
-
// Host app passes showModal prop, but some integrations may use invokeBot
|
|
10077
10625
|
React.useEffect(() => {
|
|
10078
|
-
|
|
10079
|
-
|
|
10080
|
-
|
|
10081
|
-
setShowModal(shouldShow);
|
|
10626
|
+
if (props.invokeBot) {
|
|
10627
|
+
setMinimizedMode(!props.invokeBot);
|
|
10628
|
+
setShowModal(props.invokeBot);
|
|
10082
10629
|
}
|
|
10083
|
-
}, [props.
|
|
10084
|
-
// Also call props.setShowModal when internal state changes (two-way binding)
|
|
10085
|
-
React.useEffect(() => {
|
|
10086
|
-
if (props.setShowModal && typeof props.setShowModal === 'function') {
|
|
10087
|
-
props.setShowModal(showModal);
|
|
10088
|
-
}
|
|
10089
|
-
}, [showModal]);
|
|
10630
|
+
}, [props.invokeBot]);
|
|
10090
10631
|
React.useEffect(() => {
|
|
10091
10632
|
let screenNameStored = localStorage.getItem("smartBotScreenName");
|
|
10092
10633
|
let currentAppLinkStored = localStorage.getItem("smartBotCurrentAppLink");
|
|
@@ -10184,17 +10725,17 @@ const SmartBot = (props) => {
|
|
|
10184
10725
|
}, [notificationData, baseUrl, currentAgentId, currentSessionId]);
|
|
10185
10726
|
React.useEffect(() => {
|
|
10186
10727
|
// Continue with current mode specific logic
|
|
10187
|
-
if (chatDataInfoRef?.current[currentMode]?.conversations?.[
|
|
10728
|
+
if (chatDataInfoRef?.current[currentMode]?.conversations?.[activeConversationId]?.messages
|
|
10188
10729
|
?.length > 0) {
|
|
10189
10730
|
// setConversation(chatDataInfoRef?.current[currentMode]?.conversations?.[1]?.messages);
|
|
10190
|
-
let chatDataInfoRefLength = chatDataInfoRef?.current[currentMode]?.conversations?.[
|
|
10731
|
+
let chatDataInfoRefLength = chatDataInfoRef?.current[currentMode]?.conversations?.[activeConversationId]?.messages
|
|
10191
10732
|
?.length;
|
|
10192
|
-
let chatDataInfoRefLastMessage = chatDataInfoRef?.current[currentMode]?.conversations?.[
|
|
10733
|
+
let chatDataInfoRefLastMessage = chatDataInfoRef?.current[currentMode]?.conversations?.[activeConversationId]?.messages[chatDataInfoRefLength - 1];
|
|
10193
10734
|
if (chatDataInfoRefLastMessage?.bodyType === "stream") {
|
|
10194
|
-
let newChatData = chatDataState?.[currentMode]?.conversations?.[
|
|
10735
|
+
let newChatData = chatDataState?.[currentMode]?.conversations?.[activeConversationId]?.messages;
|
|
10195
10736
|
let newChatDataLength = newChatData?.length - 1;
|
|
10196
10737
|
if (newChatDataLength) {
|
|
10197
|
-
chatDataInfoRef.current[currentMode].conversations[
|
|
10738
|
+
chatDataInfoRef.current[currentMode].conversations[activeConversationId].messages[chatDataInfoRefLength - 1] = lodash.cloneDeep(newChatData?.[newChatDataLength]);
|
|
10198
10739
|
}
|
|
10199
10740
|
}
|
|
10200
10741
|
// let chatDataForReference = JSON.stringify(
|
|
@@ -10217,7 +10758,7 @@ const SmartBot = (props) => {
|
|
|
10217
10758
|
customChatConfig: customChatConfig,
|
|
10218
10759
|
loader: loader,
|
|
10219
10760
|
};
|
|
10220
|
-
const allMessages = chatDataInfoRef?.current[currentMode]?.conversations?.[
|
|
10761
|
+
const allMessages = chatDataInfoRef?.current[currentMode]?.conversations?.[activeConversationId]?.messages || [];
|
|
10221
10762
|
const lastBotMessageIndex = allMessages.reduce((lastIdx, msg, idx) => msg.userType === "bot" ? idx : lastIdx, -1);
|
|
10222
10763
|
allMessages.forEach((message, index) => {
|
|
10223
10764
|
if (message.userType === "bot") {
|
|
@@ -10230,8 +10771,20 @@ const SmartBot = (props) => {
|
|
|
10230
10771
|
// />
|
|
10231
10772
|
// ;
|
|
10232
10773
|
message.isFormDisabled = index !== lastBotMessageIndex;
|
|
10233
|
-
|
|
10774
|
+
let originalUtilityObject = message.utilityObject;
|
|
10775
|
+
let newMessage = lodash.cloneDeep(message);
|
|
10776
|
+
if (originalUtilityObject) {
|
|
10777
|
+
newMessage.utilityObject = originalUtilityObject;
|
|
10778
|
+
}
|
|
10779
|
+
message.jsx = (jsxRuntime.jsx(BotMessage, { botData: newMessage, state: loadingState, handleLikeDislike: handleLikeDislike, props: properties }));
|
|
10234
10780
|
message.firstMessage = true;
|
|
10781
|
+
let actualProps = {
|
|
10782
|
+
botData: newMessage,
|
|
10783
|
+
state: loadingState,
|
|
10784
|
+
handleLikeDislike: handleLikeDislike,
|
|
10785
|
+
props: properties,
|
|
10786
|
+
};
|
|
10787
|
+
message.actualProps = actualProps;
|
|
10235
10788
|
// message.enableLikes = true;
|
|
10236
10789
|
}
|
|
10237
10790
|
});
|
|
@@ -10239,7 +10792,15 @@ const SmartBot = (props) => {
|
|
|
10239
10792
|
let newChat = lodash.cloneDeep(chatDataInfoRef?.current[currentMode]);
|
|
10240
10793
|
setConversation(newChat);
|
|
10241
10794
|
}
|
|
10242
|
-
|
|
10795
|
+
else if (showModal) {
|
|
10796
|
+
// Current mode has no messages — clear conversation so the previous
|
|
10797
|
+
// mode's components (including any active StreamedContent) unmount.
|
|
10798
|
+
// Without this, switching from agent→navigation while agent is streaming
|
|
10799
|
+
// would keep the agent's StreamedContent mounted and its response would
|
|
10800
|
+
// render in the navigation tab.
|
|
10801
|
+
setConversation({});
|
|
10802
|
+
}
|
|
10803
|
+
}, [chatDataState, currentMode, activeConversationId]);
|
|
10243
10804
|
const fetchLegacyAgentInfo = async () => {
|
|
10244
10805
|
try {
|
|
10245
10806
|
let legacyAgentScreenData = await utils.fetchLegacyAgentScreen();
|
|
@@ -10268,7 +10829,7 @@ const SmartBot = (props) => {
|
|
|
10268
10829
|
return;
|
|
10269
10830
|
}
|
|
10270
10831
|
if (currentMode !== "agent") {
|
|
10271
|
-
fetchUserResultsFromQuery({}, false, userInput);
|
|
10832
|
+
fetchUserResultsFromQuery({}, false, userInput, activeConversationId);
|
|
10272
10833
|
}
|
|
10273
10834
|
else if (customChatConfig?.useMiddleware) {
|
|
10274
10835
|
let middleWareFunction = await getDynamicFunction(customChatConfig.middleWareFunctionPath, customChatConfig.middleWareFunctionName);
|
|
@@ -10278,8 +10839,6 @@ const SmartBot = (props) => {
|
|
|
10278
10839
|
sessionId: currentSessionId,
|
|
10279
10840
|
baseUrl: baseUrl,
|
|
10280
10841
|
uniqueChatId: uniqueChatId,
|
|
10281
|
-
userExplicitInput: userExplicitInput,
|
|
10282
|
-
textWithColumnNames: textWithColumnNames,
|
|
10283
10842
|
};
|
|
10284
10843
|
let middleWareResponse = await middleWareFunction(data, chatBotInfoRef);
|
|
10285
10844
|
if (middleWareResponse) {
|
|
@@ -10334,7 +10893,8 @@ const SmartBot = (props) => {
|
|
|
10334
10893
|
setInitValue: setInitValue,
|
|
10335
10894
|
uniqueChatId: uniqueChatId,
|
|
10336
10895
|
currentAgentChatId: currentAgentChatId,
|
|
10337
|
-
additionalArgs: lodash.isEmpty(userInput) ? additionalArgs : {}
|
|
10896
|
+
additionalArgs: lodash.isEmpty(userInput) ? additionalArgs : {},
|
|
10897
|
+
activeConversationId: activeConversationId,
|
|
10338
10898
|
});
|
|
10339
10899
|
setUserInput("");
|
|
10340
10900
|
}
|
|
@@ -10481,13 +11041,38 @@ const SmartBot = (props) => {
|
|
|
10481
11041
|
setBaseUrl(customBaseUrl);
|
|
10482
11042
|
}
|
|
10483
11043
|
}, [forceOpen]);
|
|
10484
|
-
|
|
11044
|
+
const [historyPanelData, setHistoryPanelData] = React.useState([]);
|
|
11045
|
+
const { fetchConversations, saveCurrentChat, renameConversation, deleteConversation, fetchConversationChats, } = useConversationManagement(chatDataRef, currentMode, activeConversationId, setActiveConversationId, setChatDataState, selectedModule, setSelectedModule, isModuleChanged, setIsModuleChanged, undefined, undefined, chatDataInfoRef, setHistoryPanelData, processResponse);
|
|
11046
|
+
const handleHistoryMenuAction = React.useCallback(async (action, conversationData, renamedConversation = "") => {
|
|
11047
|
+
const conversationId = conversationData?.conversation_id;
|
|
11048
|
+
if (action === "rename") {
|
|
11049
|
+
await renameConversation(conversationId, renamedConversation, "agent");
|
|
11050
|
+
}
|
|
11051
|
+
else if (action === "delete") {
|
|
11052
|
+
await deleteConversation(conversationId, "agent");
|
|
11053
|
+
}
|
|
11054
|
+
fetchConversations(null, "agent");
|
|
11055
|
+
}, [renameConversation, deleteConversation, fetchConversations]);
|
|
11056
|
+
return (jsxRuntime.jsxs("div", { className: `${classes.agentStyleOverride} ${partialClose ? classes.hideBotStyle : ""} `, children: [jsxRuntime.jsx(MemoryModal, { isModalOpen: isModalOpen, setIsModalOpen: setIsModalOpen, displaySnackMessages: displaySnackMessages }), jsxRuntime.jsx(UploadModal, { isUploadModalOpen: isUploadModalOpen, setIsUploadModalOpen: setIsUploadModalOpen, displaySnackMessages: displaySnackMessages }), jsxRuntime.jsx(impactUiV3.ChatBotComponent, { isFullWidth: forceOpen, userName: userName, showHistoryPanel: false, customInputComponent: currentMode === "agent" ? (jsxRuntime.jsx(ChatbotInput, { newChatScreen: newChatScreen, inputValue: userInput, setInputValue: setUserInput, isStopIcon: isStop, onSendIconClick: onSendIconClick, onStopIconClick: onStopIconClick, currentMode: currentMode, filterOptions: filterOptions, onSaveClick: saveCurrentChat })) : null, isChatBotOpen: showModal || forceOpen, historyPanelData: historyPanelData, onHistorySearchChange: (params) => { console.log("History Search Change", params); }, onHistorySelectConversation: (params) => {
|
|
11057
|
+
console.log("History Select Conversation", params);
|
|
11058
|
+
setNewChatScreen(false);
|
|
11059
|
+
setShowChatPlaceholder(false);
|
|
11060
|
+
fetchConversationChats(params?.conversation_id, "agent");
|
|
11061
|
+
}, onHistoryPanelClick: (p1, p2) => {
|
|
11062
|
+
console.log("History", p1, p2);
|
|
11063
|
+
fetchConversations(null, "agent");
|
|
11064
|
+
}, onHistoryMenuAction: (action, conversationData, renamedConversation) => {
|
|
11065
|
+
console.log("History Menu Action", action, conversationData);
|
|
11066
|
+
handleHistoryMenuAction(action, conversationData, renamedConversation);
|
|
11067
|
+
},
|
|
10485
11068
|
// landingScreen={true}
|
|
10486
11069
|
handleNewChatClick: () => {
|
|
10487
11070
|
localStorage.setItem("isStreaming", "false");
|
|
10488
11071
|
dispatch(smartBotActions.setChatbotContext({}));
|
|
10489
11072
|
setConversation([]);
|
|
10490
|
-
chatDataInfoRef.current[currentMode] =
|
|
11073
|
+
chatDataInfoRef.current[currentMode] = {
|
|
11074
|
+
conversations: {},
|
|
11075
|
+
};
|
|
10491
11076
|
setChatDataState({});
|
|
10492
11077
|
if (currentMode === "agent") {
|
|
10493
11078
|
setShowChatPlaceholder(true);
|
|
@@ -10556,8 +11141,10 @@ const SmartBot = (props) => {
|
|
|
10556
11141
|
// );
|
|
10557
11142
|
// return;
|
|
10558
11143
|
// } else {
|
|
11144
|
+
const agentConversations = chatDataInfoRef?.current[params?.name?.toLowerCase()]?.conversations;
|
|
11145
|
+
const firstConversationId = agentConversations ? Object.keys(agentConversations)[0] : undefined;
|
|
10559
11146
|
if (params?.name?.toLowerCase() === "agent") {
|
|
10560
|
-
if (!lodash.isEmpty(
|
|
11147
|
+
if (!lodash.isEmpty(agentConversations?.[firstConversationId]?.messages)) {
|
|
10561
11148
|
setShowChatPlaceholder(false);
|
|
10562
11149
|
}
|
|
10563
11150
|
else {
|
|
@@ -10565,6 +11152,9 @@ const SmartBot = (props) => {
|
|
|
10565
11152
|
}
|
|
10566
11153
|
}
|
|
10567
11154
|
setCurrentMode(params?.name?.toLowerCase());
|
|
11155
|
+
if (firstConversationId) {
|
|
11156
|
+
setActiveConversationId(firstConversationId);
|
|
11157
|
+
}
|
|
10568
11158
|
localStorage.setItem("currentModeData", params?.name?.toLowerCase());
|
|
10569
11159
|
setNewChatScreen(false);
|
|
10570
11160
|
activeTab.current.activeTab = "agent";
|
|
@@ -10588,7 +11178,9 @@ const SmartBot = (props) => {
|
|
|
10588
11178
|
// return;
|
|
10589
11179
|
// } else {
|
|
10590
11180
|
let currentModeValue = params?.name?.toLowerCase();
|
|
10591
|
-
|
|
11181
|
+
const modeConversations = chatDataInfoRef?.current[currentModeValue]?.conversations;
|
|
11182
|
+
const firstConversationId = modeConversations ? Object.keys(modeConversations)[0] : undefined;
|
|
11183
|
+
if (!lodash.isEmpty(modeConversations?.[firstConversationId]?.messages)) {
|
|
10592
11184
|
setNewChatScreen(false);
|
|
10593
11185
|
}
|
|
10594
11186
|
else {
|
|
@@ -10609,13 +11201,16 @@ const SmartBot = (props) => {
|
|
|
10609
11201
|
// setNewChatScreen(true);
|
|
10610
11202
|
setIsStop(false);
|
|
10611
11203
|
setCurrentMode(params?.name?.toLowerCase());
|
|
11204
|
+
if (firstConversationId) {
|
|
11205
|
+
setActiveConversationId(firstConversationId);
|
|
11206
|
+
}
|
|
10612
11207
|
// setConversation([]);
|
|
10613
11208
|
// chatDataInfoRef.current[currentMode] = [];
|
|
10614
11209
|
// }
|
|
10615
11210
|
},
|
|
10616
11211
|
icon: jsxRuntime.jsx(SvgNavigationIcon, {}),
|
|
10617
11212
|
},
|
|
10618
|
-
], utilityList: utilityList, isAssistantThinking: loader, isCustomScreen: showChatPlaceholder, customScreenJsx: jsxRuntime.jsx(ChatPlaceholder, { dateFormat: dateFormat, chatDataRef: chatDataRef, currentMode: currentMode, setShowChatPlaceholder: setShowChatPlaceholder, setLoader: setLoader, setCurrentAgentId: setCurrentAgentId, baseUrl: baseUrl, setBaseUrl: setBaseUrl, setCurrentSessionId: setCurrentSessionId, customChatConfig: customChatConfig, chatDataInfoRef: chatDataInfoRef, setChatDataState: setChatDataState, userInput: userInput, legacyAgentScreen: legacyAgentScreen, activeConversationId: activeConversationId, chatBodyRef: chatBodyRef, chatbotContext: chatbotContext, setInitValue: setInitValue, setSessionId: setSessionId, thinkingContent: thinkingContext?.thinkingContent, setThinkingContent: setThinkingContent, isThinking: isThinking, setIsThinking: setIsThinking, chatId: chatId, setChatId: setChatId, isStop: isStop, setIsStop: setIsStop, functionsRef: functionsRef, functionsState: functionsState, setFunctionsState: setFunctionsState, thinkingHeaderMessage: thinkingContext?.thinkingHeaderMessage, setThinkingHeaderMessage: setThinkingHeaderMessage, uniqueChatId: uniqueChatId, setUniqueChatId: setUniqueChatId, fieldNumber: fieldNumber, setFieldNumber: setFieldNumber, setAdditionalArgs: setAdditionalArgs, displayQuestions: displayQuestions, questions: questions }), inputText: userInput, threadList: ["Home"], hideMenuArrow: hideMenu, newChatScreen: newChatScreen, isModuleListLoading: modulesLoading, suggestionBanner: {
|
|
11213
|
+
], utilityList: utilityList, isAssistantThinking: loader, isCustomScreen: showChatPlaceholder, customScreenJsx: jsxRuntime.jsx(ChatPlaceholder, { dateFormat: dateFormat, chatDataRef: chatDataRef, currentMode: currentMode, setShowChatPlaceholder: setShowChatPlaceholder, setLoader: setLoader, setCurrentAgentId: setCurrentAgentId, baseUrl: baseUrl, setBaseUrl: setBaseUrl, setCurrentSessionId: setCurrentSessionId, customChatConfig: customChatConfig, chatDataInfoRef: chatDataInfoRef, setChatDataState: setChatDataState, userInput: userInput, legacyAgentScreen: legacyAgentScreen, activeConversationId: activeConversationId, chatBodyRef: chatBodyRef, chatbotContext: chatbotContext, setInitValue: setInitValue, setSessionId: setSessionId, thinkingContent: thinkingContext?.thinkingContent, setThinkingContent: setThinkingContent, isThinking: isThinking, setIsThinking: setIsThinking, chatId: chatId, setChatId: setChatId, isStop: isStop, setIsStop: setIsStop, functionsRef: functionsRef, functionsState: functionsState, setFunctionsState: setFunctionsState, thinkingHeaderMessage: thinkingContext?.thinkingHeaderMessage, setThinkingHeaderMessage: setThinkingHeaderMessage, uniqueChatId: uniqueChatId, setUniqueChatId: setUniqueChatId, fieldNumber: fieldNumber, setFieldNumber: setFieldNumber, setAdditionalArgs: setAdditionalArgs, displayQuestions: displayQuestions, questions: questions, setActiveConversationId: setActiveConversationId }), inputText: userInput, threadList: ["Home"], hideMenuArrow: hideMenu, newChatScreen: newChatScreen, isModuleListLoading: modulesLoading, suggestionBanner: {
|
|
10619
11214
|
freeTextHeading: "Try adding more details :",
|
|
10620
11215
|
freeTextContent: "Alan works better when you provide more context and pointed questions",
|
|
10621
11216
|
}, isStopIcon: isStop, onStopIconClick: onStopIconClick, footerText: "AI-generated responses may contain errors\u2014please verify important information", showSuggestionBanner: showSuggestionBanner, onCloseSuggestionBanner: () => {
|
|
@@ -10632,6 +11227,9 @@ const SmartBot = (props) => {
|
|
|
10632
11227
|
}
|
|
10633
11228
|
const likeDislikeKey = `${params?.response_heading || params?.screen_name}_${params?.timeStamp}`;
|
|
10634
11229
|
handleLikeDislike(likeDislikeKey, false, params?.bodyText, params2);
|
|
11230
|
+
}, handleSaveChat: () => {
|
|
11231
|
+
// Handle save chat logic here
|
|
11232
|
+
saveCurrentChat();
|
|
10635
11233
|
} })] }));
|
|
10636
11234
|
};
|
|
10637
11235
|
|