impact-chatbot 2.3.43 → 2.3.47

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
@@ -5073,6 +5073,17 @@ const sseevent = (message, messageToStoreRef) => {
5073
5073
  messageToStoreRef.current.chatData.response =
5074
5074
  messageToStoreRef.current.chatData.response +
5075
5075
  "There is an error, please reach out to IA with this use case.";
5076
+ // Still process completed/follow-up status even on error chunks
5077
+ // so that initValue is set correctly and dummyButton is suppressed
5078
+ if (parsedData?.status === "completed" ||
5079
+ parsedData?.status === "follow-up") {
5080
+ messageToStoreRef.current.initValue = true;
5081
+ messageToStoreRef.current.sessionId = "";
5082
+ messageToStoreRef.current.uniqueChatId = parsedData?.chat_id
5083
+ ? parsedData.chat_id
5084
+ : "";
5085
+ messageToStoreRef.current.status = parsedData?.status;
5086
+ }
5076
5087
  return new MessageEvent(type, { data: data });
5077
5088
  }
5078
5089
  if (parsedData?.status === "thinking") {
@@ -5273,6 +5284,9 @@ const stepFormStreamControl = {
5273
5284
  chatId: "",
5274
5285
  agentId: "",
5275
5286
  baseUrl: "",
5287
+ // Completed/follow-up state — persists across ButtonContent remounts
5288
+ initValue: false,
5289
+ uniqueChatId: "",
5276
5290
  };
5277
5291
  const useStyles$5 = makeStyles((theme) => ({
5278
5292
  buttonContainer: {
@@ -5335,8 +5349,15 @@ const ButtonContent = ({ bodyText, isFormDisabled = false, isStepFormSubmit = fa
5335
5349
  };
5336
5350
  const callInitApiStream = (userInput) => {
5337
5351
  // Prefer module-level values (set synchronously by StreamedContent), fall back to sessionStorage
5338
- const sessionId = stepFormStreamControl.sessionId || sessionStorage.getItem("stepForm_sessionId") || "";
5339
- const chatId = stepFormStreamControl.chatId || sessionStorage.getItem("stepForm_chatId") || "";
5352
+ // If a previous completed/follow-up response updated the state, use those values.
5353
+ // Read from module-level stepFormStreamControl (survives remounts) instead of local messageStoreRef.
5354
+ const hasCompletedState = stepFormStreamControl.initValue === true;
5355
+ const sessionId = hasCompletedState
5356
+ ? (stepFormStreamControl.sessionId ?? "")
5357
+ : (stepFormStreamControl.sessionId || sessionStorage.getItem("stepForm_sessionId") || "");
5358
+ const chatId = hasCompletedState
5359
+ ? (stepFormStreamControl.uniqueChatId ?? "")
5360
+ : (stepFormStreamControl.chatId || sessionStorage.getItem("stepForm_chatId") || "");
5340
5361
  const agentId = stepFormStreamControl.agentId || sessionStorage.getItem("stepForm_agentId") || "";
5341
5362
  const baseUrl = stepFormStreamControl.baseUrl || sessionStorage.getItem("stepForm_baseUrl") || "";
5342
5363
  const payload = {
@@ -5344,9 +5365,14 @@ const ButtonContent = ({ bodyText, isFormDisabled = false, isStepFormSubmit = fa
5344
5365
  session_id: sessionId,
5345
5366
  chat_id: chatId,
5346
5367
  user_input: userInput,
5347
- init: false,
5368
+ init: hasCompletedState ? true : false,
5348
5369
  delay: 0.3,
5349
5370
  };
5371
+ // Reset the flag so subsequent calls don't re-use stale completed state
5372
+ if (hasCompletedState) {
5373
+ messageStoreRef.current.initValue = false;
5374
+ stepFormStreamControl.initValue = false;
5375
+ }
5350
5376
  const endPoint = baseUrl
5351
5377
  ? `${BASE_API}${baseUrl}/chatbot/agent/init`
5352
5378
  : `${BASE_API}/core/chatbot/agent/init`;
@@ -5388,6 +5414,10 @@ const ButtonContent = ({ bodyText, isFormDisabled = false, isStepFormSubmit = fa
5388
5414
  console.log("[ButtonContent] SSE chunk:", data);
5389
5415
  if (data?.status === "step" || data?.status === "step_form" || data?.status === "questions" || data?.status === "thinking" || data?.status === "widget") {
5390
5416
  chunksRef.push(data);
5417
+ // Dispatch widget chunks immediately for real-time rendering
5418
+ if (data?.status === "widget") {
5419
+ dispatch(setStepFormStreamData({ status: "widget_chunk", chunks: [data] }));
5420
+ }
5391
5421
  // If this chunk also carries [DONE], dispatch collected chunks now
5392
5422
  if (data?.message === "[DONE]") {
5393
5423
  stepFormStreamControl.isStreaming = false;
@@ -5396,13 +5426,25 @@ const ButtonContent = ({ bodyText, isFormDisabled = false, isStepFormSubmit = fa
5396
5426
  dispatch(setStepFormStreamData({ status: "done", chunks: [...chunksRef] }));
5397
5427
  }
5398
5428
  }
5399
- else if (data?.status === "completed" || data?.message === "[DONE]") {
5429
+ else if (data?.status === "completed" || data?.status === "follow-up" || data?.message === "[DONE]") {
5430
+ // Update messageStoreRef the same way AxiosEventSource does for completed/follow-up
5431
+ if (data?.status === "completed" || data?.status === "follow-up") {
5432
+ messageStoreRef.current.initValue = true;
5433
+ messageStoreRef.current.sessionId = "";
5434
+ messageStoreRef.current.uniqueChatId = data?.chat_id ? data.chat_id : "";
5435
+ // Also persist on module-level object so it survives ButtonContent remounts
5436
+ stepFormStreamControl.initValue = true;
5437
+ stepFormStreamControl.sessionId = "";
5438
+ stepFormStreamControl.uniqueChatId = data?.chat_id ? data.chat_id : "";
5439
+ }
5400
5440
  // Stream ended — dispatch all collected chunks at once
5401
5441
  stepFormStreamControl.isStreaming = false;
5402
5442
  stepFormStreamControl.abort = null;
5403
5443
  window.dispatchEvent(new CustomEvent("stepFormStreamEnd"));
5404
- // Signal tab switch to agent_response when status is "completed"
5405
- if (data?.status === "completed") {
5444
+ // Signal tab switch to agent_response when status is "completed",
5445
+ // but only if the response doesn't contain a new step_form that needs user interaction
5446
+ const hasStepForm = chunksRef.some((c) => c.status === "step_form");
5447
+ if (data?.status === "completed" && !hasStepForm) {
5406
5448
  window.dispatchEvent(new CustomEvent("stepFormStreamCompleted"));
5407
5449
  }
5408
5450
  dispatch(setStepFormStreamData({ status: "done", chunks: [...chunksRef] }));
@@ -6512,10 +6554,8 @@ const getQuestionStatus$1 = (questionSteps) => {
6512
6554
  /**
6513
6555
  * Renders a single progress bar item (main point + sub-items)
6514
6556
  */
6515
- const ProgressBarItem$1 = ({ question, questionSteps, isLast, classes, formData, showSavedFilters = true, isFormDisabled, isRestreaming = false, onAllSubItemsAnimated = undefined }) => {
6516
- const baseStatus = getQuestionStatus$1(questionSteps);
6517
- // When restreaming and this is the last item, show as in-progress
6518
- const status = (isRestreaming && isLast) ? "in-progress" : baseStatus;
6557
+ const ProgressBarItem$1 = ({ question, questionSteps, isLast, classes, formData, showSavedFilters = true, isFormDisabled, onAllSubItemsAnimated = undefined }) => {
6558
+ const status = getQuestionStatus$1(questionSteps);
6519
6559
  const animatedCountRef = useRef(0);
6520
6560
  const [isExpanded, setIsExpanded] = useState(true);
6521
6561
  const dotClass = status === "completed"
@@ -6559,8 +6599,14 @@ const Steps$1 = ({ steps, setSteps, done, setTabValue, setDone, finalStepDone, s
6559
6599
  const lastQuestionCompleted = lastQuestionSteps &&
6560
6600
  lastQuestionSteps.length > 0 &&
6561
6601
  lastQuestionSteps.every((s) => s.step_status === "completed");
6602
+ const hasStepFormData = Object.keys(stepFormDataMap).length > 0;
6562
6603
  useEffect(() => {
6563
6604
  if (done) {
6605
+ // Don't auto-switch to agent_response tab when there's a step form pending user interaction
6606
+ if (hasStepFormData) {
6607
+ setFinalStepDone(true);
6608
+ return;
6609
+ }
6564
6610
  if (!finalStepDone) {
6565
6611
  if (currentMode === "navigation") {
6566
6612
  let updatedSteps = steps.map((step) => ({
@@ -6610,7 +6656,7 @@ const Steps$1 = ({ steps, setSteps, done, setTabValue, setDone, finalStepDone, s
6610
6656
  step_status: "not-completed",
6611
6657
  },
6612
6658
  ];
6613
- return (jsx("div", { className: classes.progressBarContainer, children: jsx(ProgressBarItem$1, { question: fallbackQuestion, questionSteps: fallbackSteps, isLast: true, classes: classes, formData: null, isFormDisabled: isFormDisabled, showSavedFilters: true }) }));
6659
+ return (jsx("div", { className: classes.progressBarContainer, children: jsx(ProgressBarItem$1, { question: fallbackQuestion, questionSteps: fallbackSteps, isLast: true, classes: classes, formData: null, isFormDisabled: isFormDisabled }) }));
6614
6660
  }
6615
6661
  return (jsxs("div", { className: classes.progressBarContainer, children: [questions.map((question, index) => {
6616
6662
  const questionData = questionsStepsMap[question];
@@ -6633,17 +6679,40 @@ const Steps$1 = ({ steps, setSteps, done, setTabValue, setDone, finalStepDone, s
6633
6679
  }, children: jsx(ProgressBarItem$1, { question: "Thinking", questionSteps: [{ header: "", sub_header: "", step_status: "not-completed" }], isLast: true, classes: classes, formData: null, isFormDisabled: isFormDisabled }) }))] }));
6634
6680
  };
6635
6681
 
6682
+ const renderWidgetItem = (item, index) => {
6683
+ try {
6684
+ const parsedData = parseResponse(item, item.type, "", "", true);
6685
+ if (!parsedData)
6686
+ return null;
6687
+ const key = `streaming-widget-${index}`;
6688
+ switch (parsedData.bodyType) {
6689
+ case "text":
6690
+ return jsx(TextContent, { bodyText: parsedData.bodyText, botData: parsedData }, key);
6691
+ case "table":
6692
+ return jsx(TableContent, { bodyText: parsedData.bodyText }, key);
6693
+ case "graph":
6694
+ return jsx(GraphContent, { bodyText: parsedData.bodyText }, key);
6695
+ default:
6696
+ return null;
6697
+ }
6698
+ }
6699
+ catch (e) {
6700
+ console.error("[AgentResponse] renderWidgetItem error:", e);
6701
+ return null;
6702
+ }
6703
+ };
6636
6704
  const AgentResponse$1 = (props) => {
6637
- const { content, isStreaming } = props;
6705
+ const { content, isStreaming, streamingWidgetData = [] } = props;
6638
6706
  const classes = useStyles$4();
6639
6707
  const chatClasses = useStyles$7();
6640
- return (jsx("div", { className: chatClasses.agentResponseContainer, children: content ? (jsxs(Typography, { className: chatClasses.bodyTextStyling, children: [jsx(TextRenderer, { text: content }), isStreaming && jsx("span", { className: classes.cursor })] })) : (
6641
- // Show cursor even when no content yet
6642
- isStreaming && jsx("span", { className: classes.cursor })) }));
6708
+ const renderedWidgets = streamingWidgetData
6709
+ .map((item, index) => renderWidgetItem(item, index))
6710
+ .filter(Boolean);
6711
+ return (jsxs("div", { className: chatClasses.agentResponseContainer, children: [content ? (jsxs(Typography, { className: chatClasses.bodyTextStyling, children: [jsx(TextRenderer, { text: content }), isStreaming && renderedWidgets.length === 0 && jsx("span", { className: classes.cursor })] })) : null, renderedWidgets.length > 0 && (jsx("div", { className: "streaming-widget-content", children: renderedWidgets })), isStreaming && (renderedWidgets.length > 0 || !content) && (jsx("span", { className: classes.cursor }))] }));
6643
6712
  };
6644
6713
 
6645
6714
  const StepsResponseTab = (props) => {
6646
- const { steps, setSteps, stepsDone, setStepsDone, finalStepDone, setFinalStepDone, content, isStreaming, stepChange, currentMode, questions, questionsStepsMap, stepFormDataMap, isFormDisabled, } = props;
6715
+ const { steps, setSteps, stepsDone, setStepsDone, finalStepDone, setFinalStepDone, content, isStreaming, stepChange, currentMode, questions, questionsStepsMap, stepFormDataMap, isFormDisabled, streamingWidgetData, } = props;
6647
6716
  const [tabValue, setTabValue] = useState("steps");
6648
6717
  const handleChangeTabValue = (_event, newValue) => {
6649
6718
  setTabValue(newValue);
@@ -6661,7 +6730,7 @@ const StepsResponseTab = (props) => {
6661
6730
  },
6662
6731
  ], tabPanels: [
6663
6732
  jsx(Steps$1, { steps: steps, setSteps: setSteps, done: stepsDone, setDone: setStepsDone, setTabValue: setTabValue, finalStepDone: finalStepDone, setFinalStepDone: setFinalStepDone, stepChange: stepChange, currentMode: currentMode, questions: questions, questionsStepsMap: questionsStepsMap, stepFormDataMap: stepFormDataMap, isFormDisabled: isFormDisabled }),
6664
- jsx(AgentResponse$1, { content: content, isStreaming: isStreaming }),
6733
+ jsx(AgentResponse$1, { content: content, isStreaming: isStreaming, streamingWidgetData: streamingWidgetData }),
6665
6734
  ], value: tabValue }) }));
6666
6735
  };
6667
6736
 
@@ -6711,6 +6780,7 @@ const StreamedContent = ({ botData }) => {
6711
6780
  // const [thinkingContent, setThinkingContent] = useState("");
6712
6781
  const [thinkDone, setThinkDone] = useState(false);
6713
6782
  const [isStreaming, setIsStreaming] = useState(true);
6783
+ const [streamingWidgetData, setStreamingWidgetData] = useState([]);
6714
6784
  const [thinkingStarted, setThinkingStarted] = useState(false);
6715
6785
  const [isStreamingDone, setIsStreamingDone] = useState(false);
6716
6786
  const [isThinking, setIsThinking] = useState(false);
@@ -6885,7 +6955,7 @@ const StreamedContent = ({ botData }) => {
6885
6955
  }));
6886
6956
  return;
6887
6957
  }
6888
- if (data?.message || data?.status === "step" || data?.status === "step_form" || data?.status === "thinking" || data?.status === "questions") {
6958
+ if (data?.message || data?.status === "step" || data?.status === "step_form" || data?.status === "thinking" || data?.status === "questions" || data?.status === "widget") {
6889
6959
  if (data.status === "questions") {
6890
6960
  const incomingQuestions = data.widget_data?.[0]?.questions || [];
6891
6961
  questionsRef.current = incomingQuestions;
@@ -6998,6 +7068,15 @@ const StreamedContent = ({ botData }) => {
6998
7068
  : [data.widget_data];
6999
7069
  const currentIntent = data.current_intent || formWidgetData?.[0]?.current_intent;
7000
7070
  if (currentIntent) {
7071
+ // Auto-create question/intent entry if no prior step chunk created it
7072
+ if (!questionsStepsMapRef.current[currentIntent]) {
7073
+ questionsStepsMapRef.current[currentIntent] = [];
7074
+ if (!questionsRef.current.includes(currentIntent)) {
7075
+ questionsRef.current = [...questionsRef.current, currentIntent];
7076
+ setQuestions([...questionsRef.current]);
7077
+ }
7078
+ setQuestionsStepsMap(cloneDeep(questionsStepsMapRef.current));
7079
+ }
7001
7080
  const sendButton = document.getElementById("chat-input-send-button");
7002
7081
  const stepFormSubmitButton = {
7003
7082
  type: "button",
@@ -7037,12 +7116,20 @@ const StreamedContent = ({ botData }) => {
7037
7116
  stepFormStreamControl.baseUrl = _burl;
7038
7117
  // If this is the [DONE] chunk, mark streaming as complete
7039
7118
  if (data.message === "[DONE]") {
7119
+ setStepsDone(true);
7040
7120
  setIsStreamingDone(true);
7041
7121
  const doneState = streamStateMap.get(streamKey);
7042
7122
  if (doneState)
7043
7123
  doneState.completed = true;
7044
7124
  }
7045
7125
  }
7126
+ else if (data.status === "widget") {
7127
+ // Render widget data immediately as it arrives during streaming
7128
+ const widgetItems = isArray(data.widget_data)
7129
+ ? data.widget_data
7130
+ : [data.widget_data];
7131
+ setStreamingWidgetData((prev) => [...prev, ...widgetItems]);
7132
+ }
7046
7133
  else if (data.message !== "[DONE]") {
7047
7134
  if (!thinkingDoneRef?.current && currentMode === "agent") {
7048
7135
  thinkingDoneRef.current = true;
@@ -7125,6 +7212,13 @@ const StreamedContent = ({ botData }) => {
7125
7212
  const store = messageToStoreRef.current;
7126
7213
  // Restore accumulated content
7127
7214
  setContent(store.chatData?.response || "");
7215
+ // Restore widget data received so far
7216
+ if (isArray(store.appendedData) && store.appendedData.length > 0) {
7217
+ setStreamingWidgetData(store.appendedData);
7218
+ }
7219
+ else if (store.appendedData && !isArray(store.appendedData) && Object.keys(store.appendedData).length > 0) {
7220
+ setStreamingWidgetData([store.appendedData]);
7221
+ }
7128
7222
  // Restore thinking state
7129
7223
  if (store.chatData?.thinkingResponse?.thinkingStream) {
7130
7224
  thinkingContentRef.current = store.chatData.thinkingResponse.thinkingStream;
@@ -7191,15 +7285,21 @@ const StreamedContent = ({ botData }) => {
7191
7285
  dispatch(setCurrentAgentChatId(messageToStoreRef.current.uniqueChatId));
7192
7286
  }
7193
7287
  // Persist IDs for step form restream (ButtonContent reads these)
7194
- sessionStorage.setItem("stepForm_sessionId", messageToStoreRef.current.sessionId || "");
7195
- sessionStorage.setItem("stepForm_chatId", messageToStoreRef.current.uniqueChatId || "");
7196
- sessionStorage.setItem("stepForm_agentId", botData.inputBody?.agent_id || "");
7197
- sessionStorage.setItem("stepForm_baseUrl", baseUrl || "");
7198
- // Also sync module-level control object
7199
- stepFormStreamControl.sessionId = messageToStoreRef.current.sessionId || "";
7200
- stepFormStreamControl.chatId = messageToStoreRef.current.uniqueChatId || "";
7201
- stepFormStreamControl.agentId = botData.inputBody?.agent_id || "";
7202
- stepFormStreamControl.baseUrl = baseUrl || "";
7288
+ const _sid2 = messageToStoreRef.current.sessionId || "";
7289
+ const _cid2 = messageToStoreRef.current.uniqueChatId || "";
7290
+ const _aid2 = botData.inputBody?.agent_id || "";
7291
+ const _burl2 = baseUrl || "";
7292
+ sessionStorage.setItem("stepForm_sessionId", _sid2);
7293
+ sessionStorage.setItem("stepForm_chatId", _cid2);
7294
+ sessionStorage.setItem("stepForm_agentId", _aid2);
7295
+ sessionStorage.setItem("stepForm_baseUrl", _burl2);
7296
+ stepFormStreamControl.sessionId = _sid2;
7297
+ stepFormStreamControl.chatId = _cid2;
7298
+ stepFormStreamControl.agentId = _aid2;
7299
+ stepFormStreamControl.baseUrl = _burl2;
7300
+ // Persist completed/follow-up state so ButtonContent can read it after remount
7301
+ stepFormStreamControl.initValue = messageToStoreRef.current.initValue;
7302
+ stepFormStreamControl.uniqueChatId = _cid2;
7203
7303
  let appendedDataLength = 0;
7204
7304
  // Use appendedDataFromLastChunk for field number calculation like host app
7205
7305
  if (isArray(messageToStoreRef.current.appendedDataFromLastChunk)) {
@@ -7250,11 +7350,12 @@ const StreamedContent = ({ botData }) => {
7250
7350
  },
7251
7351
  },
7252
7352
  };
7353
+ const hasStepFormWidgets = !isEmpty(stepFormDataMapRef.current);
7253
7354
  processResponse(response, botData.inputBody, currentMode, botData.utilityObject.customChatConfig, {
7254
7355
  newChatData: chatDataInfoRef,
7255
7356
  isTabEnabled: true,
7256
7357
  steps: cloneDeep(stepRef.current),
7257
- currentTabValue: stepsDone ? "agent_response" : undefined,
7358
+ currentTabValue: (stepsDone && !hasStepFormWidgets) ? "agent_response" : "steps",
7258
7359
  questions: cloneDeep(questionsRef.current),
7259
7360
  questionsStepsMap: cloneDeep(questionsStepsMapRef.current),
7260
7361
  stepFormDataMap: { ...stepFormDataMapRef.current },
@@ -7340,7 +7441,7 @@ const StreamedContent = ({ botData }) => {
7340
7441
  newChatData: chatDataInfoRef,
7341
7442
  isTabEnabled: true,
7342
7443
  steps: cloneDeep(stepRef.current),
7343
- currentTabValue: stepsDone ? "agent_response" : undefined,
7444
+ currentTabValue: stepsDone ? "agent_response" : "steps",
7344
7445
  questions: cloneDeep(questionsRef.current),
7345
7446
  questionsStepsMap: cloneDeep(questionsStepsMapRef.current),
7346
7447
  stepFormDataMap: { ...stepFormDataMapRef.current },
@@ -7487,7 +7588,7 @@ const StreamedContent = ({ botData }) => {
7487
7588
  * @returns {JSX.Element} Rendered content with optional blinking cursor
7488
7589
  */
7489
7590
  const renderContent = () => {
7490
- return (jsx("div", { className: classes.streamContainer, children: jsx(StepsResponseTab, { steps: steps, stepChange: stepChange, setSteps: setSteps, stepsDone: stepsDone, setStepsDone: setStepsDone, finalStepDone: finalStepDone, setFinalStepDone: setFinalStepDone, content: content, isStreaming: isStreaming, currentMode: currentMode, questions: questions, questionsStepsMap: questionsStepsMap, stepFormDataMap: stepFormDataMap, isFormDisabled: botData?.isFormDisabled || false }) }));
7591
+ return (jsx("div", { className: classes.streamContainer, children: jsx(StepsResponseTab, { steps: steps, stepChange: stepChange, setSteps: setSteps, stepsDone: stepsDone, setStepsDone: setStepsDone, finalStepDone: finalStepDone, setFinalStepDone: setFinalStepDone, content: content, isStreaming: isStreaming, currentMode: currentMode, questions: questions, questionsStepsMap: questionsStepsMap, stepFormDataMap: stepFormDataMap, isFormDisabled: botData?.isFormDisabled || false, streamingWidgetData: streamingWidgetData }) }));
7491
7592
  };
7492
7593
  if (currentMode === "agent") {
7493
7594
  return renderContent();
@@ -7829,6 +7930,24 @@ const TabularContent = ({ steps: initialSteps, currentTabValue, children, questi
7829
7930
  setTabValue("steps");
7830
7931
  return;
7831
7932
  }
7933
+ // Handle real-time widget chunks dispatched immediately by ButtonContent
7934
+ if (payload.status === "widget_chunk") {
7935
+ const chunks = payload.chunks || [];
7936
+ const newWidgets = [];
7937
+ chunks.forEach((data) => {
7938
+ if (data.status === "widget") {
7939
+ const widgetItems = isArray$2(data.widget_data) ? data.widget_data : [data.widget_data];
7940
+ widgetItems.forEach((item) => {
7941
+ if (item)
7942
+ newWidgets.push(item);
7943
+ });
7944
+ }
7945
+ });
7946
+ if (newWidgets.length > 0) {
7947
+ setWidgetContent((prev) => [...prev, ...newWidgets]);
7948
+ }
7949
+ return;
7950
+ }
7832
7951
  // Process all collected chunks at once (done or error)
7833
7952
  const chunks = payload.chunks || [];
7834
7953
  let newSteps = cloneDeep(stepsRef.current);
@@ -7902,6 +8021,13 @@ const TabularContent = ({ steps: initialSteps, currentTabValue, children, questi
7902
8021
  const formWidgetData = isArray$2(data.widget_data) ? data.widget_data : [data.widget_data];
7903
8022
  const currentIntent = data.current_intent || formWidgetData?.[0]?.current_intent;
7904
8023
  if (currentIntent) {
8024
+ // Auto-create question/intent entry if no prior step chunk created it
8025
+ if (!newQuestionsStepsMap[currentIntent]) {
8026
+ newQuestionsStepsMap[currentIntent] = [];
8027
+ if (!newQuestions.includes(currentIntent)) {
8028
+ newQuestions.push(currentIntent);
8029
+ }
8030
+ }
7905
8031
  const submitButton = {
7906
8032
  type: "button",
7907
8033
  data: {
@@ -7922,13 +8048,7 @@ const TabularContent = ({ steps: initialSteps, currentTabValue, children, questi
7922
8048
  };
7923
8049
  }
7924
8050
  }
7925
- if (data.status === "widget") {
7926
- const widgetItems = isArray$2(data.widget_data) ? data.widget_data : [data.widget_data];
7927
- widgetItems.forEach((item) => {
7928
- if (item)
7929
- newWidgets.push(item);
7930
- });
7931
- }
8051
+ if (data.status === "widget") ;
7932
8052
  if (data.status === "content" && data.message) {
7933
8053
  newWidgets.push({ type: "text", response: data.message });
7934
8054
  }
@@ -10552,7 +10672,21 @@ const ChatbotInput = (props) => {
10552
10672
  if (newChatScreen) {
10553
10673
  clearFilterValuesCache();
10554
10674
  }
10675
+ // Auto-focus editor on mount
10676
+ setTimeout(() => {
10677
+ if (editorRef.current) {
10678
+ editorRef.current.focus();
10679
+ }
10680
+ }, 100);
10555
10681
  }, []);
10682
+ // Effect: Re-focus editor when filter set changes (e.g. chip cleared)
10683
+ useEffect(() => {
10684
+ setTimeout(() => {
10685
+ if (editorRef.current) {
10686
+ editorRef.current.focus();
10687
+ }
10688
+ }, 50);
10689
+ }, [selectedFilterSet]);
10556
10690
  // Effect: Cleanup tooltips on unmount
10557
10691
  useEffect(() => {
10558
10692
  return () => {
@@ -10762,7 +10896,8 @@ const ChatbotInput = (props) => {
10762
10896
  !target.closest("button") &&
10763
10897
  !target.closest(".chat-actions") &&
10764
10898
  !target.closest(".filter-set-trigger-wrapper") &&
10765
- !target.closest(".filter-set-chip-clear")) {
10899
+ !target.closest(".filter-set-chip-clear") &&
10900
+ !target.closest(".mention-select-wrapper")) {
10766
10901
  editorRef.current.focus();
10767
10902
  }
10768
10903
  }, children: jsxs("div", { className: `chat-input-wrapper ${isFixed ? "stacked" : ""} ${selectedFilterSet ? "has-filter-selected" : ""} ${(!isFixed || inputValue === "") && !newChatScreen && !selectedFilterSet ? "empty" : ""} ${!newChatScreen && !isFixed && !selectedFilterSet ? "single-line-textarea" : ""}`, style: { height }, children: [jsxs("div", { className: "chat-input-left-actions", children: [jsxs("div", { className: "filter-set-trigger-wrapper", ref: filterSetSelectRef, children: [jsx(Tooltip, { title: hasMentionsInEditor || showMentionSelect ? "Cannot use filter set while @ mentions are active" : "Add filter set", children: jsx("button", { type: "button", className: `filter-set-plus-btn${hasMentionsInEditor || showMentionSelect ? " disabled" : ""}`, onClick: () => {
@@ -11551,10 +11686,13 @@ const useStyles = makeStyles({
11551
11686
  buttonWrapper: {
11552
11687
  marginTop: "16px",
11553
11688
  },
11689
+ hidden: {
11690
+ display: "none",
11691
+ },
11554
11692
  });
11555
11693
  const ChatbotSaveFilterComponent = (props) => {
11556
11694
  const classes = useStyles();
11557
- const { savedFilterSets } = props;
11695
+ const { savedFilterSets, partialClose } = props;
11558
11696
  const [showFilter, setShowFilter] = useState(!isEmpty$1(savedFilterSets));
11559
11697
  /**
11560
11698
  * onFilterDashboardClick function is called when we click the apply filter
@@ -11588,6 +11726,12 @@ const ChatbotSaveFilterComponent = (props) => {
11588
11726
  setShowFilter(true);
11589
11727
  }
11590
11728
  }, [savedFilterSets]);
11729
+ useEffect(() => {
11730
+ const drawer = document.querySelector(".MuiModal-root.MuiDrawer-root");
11731
+ if (drawer) {
11732
+ drawer.style.display = partialClose ? "none" : "";
11733
+ }
11734
+ }, [partialClose]);
11591
11735
  useEffect(() => {
11592
11736
  if (!showFilter)
11593
11737
  return;
@@ -11660,7 +11804,7 @@ const ChatbotSaveFilterComponent = (props) => {
11660
11804
  observer.observe(document.body, { childList: true, subtree: true });
11661
11805
  return () => observer.disconnect();
11662
11806
  }, [showFilter]);
11663
- return (jsx(Fragment, { children: !showFilter ?
11807
+ return (jsx("div", { className: partialClose ? classes.hidden : undefined, children: !showFilter ?
11664
11808
  jsxs("div", { className: classes.container, children: [jsx(NoFilterSetSavedIcon, { width: "189px", height: "126px", className: classes.icon }), jsx("p", { className: classes.title, children: "No filter set saved!" }), jsx("p", { className: classes.subtitle, children: "Create and save a filter set to use as your default scope or apply it anytime during a conversation" }), jsx("div", { className: classes.buttonWrapper, children: jsx(Button, { variant: "primary", onClick: () => setShowFilter(true), children: "Create A Filter Set" }) })] }) :
11665
11809
  jsx("div", { children: jsx(CoreComponentScreen, { showPageHeader: false,
11666
11810
  // Filter dashboard props
@@ -12069,7 +12213,6 @@ const SmartBot = (props) => {
12069
12213
  newMessage.utilityObject = originalUtilityObject;
12070
12214
  }
12071
12215
  message.jsx = (jsx(BotMessage, { botData: newMessage, state: loadingState, handleLikeDislike: handleLikeDislike, props: properties }));
12072
- message.firstMessage = true;
12073
12216
  let actualProps = {
12074
12217
  botData: newMessage,
12075
12218
  state: loadingState,
@@ -12077,6 +12220,7 @@ const SmartBot = (props) => {
12077
12220
  props: properties,
12078
12221
  };
12079
12222
  message.actualProps = actualProps;
12223
+ message.firstMessage = true;
12080
12224
  // message.enableLikes = true;
12081
12225
  }
12082
12226
  });
@@ -12515,18 +12659,50 @@ const SmartBot = (props) => {
12515
12659
  // isActive: activeTab.current.activeTab === "agent",
12516
12660
  // initialClick: true,
12517
12661
  onClick: (params) => {
12662
+ // if (localStorage.getItem("isStreaming") === "true") {
12663
+ // displaySnackMessages(
12664
+ // "Please wait till the current request is completed",
12665
+ // "warning"
12666
+ // );
12667
+ // return;
12668
+ // } else {
12669
+ // const agentConversations = chatDataInfoRef?.current[params?.name?.toLowerCase()]?.conversations;
12670
+ // const firstConversationId = agentConversations ? Object.keys(agentConversations)[0] : undefined;
12518
12671
  if (params?.name?.toLowerCase() === "saved filters") {
12519
12672
  setNewChatScreen(false);
12520
12673
  setShowChatPlaceholder(false);
12521
12674
  setShowSavedFilters(true);
12675
+ // if (
12676
+ // !isEmpty(
12677
+ // agentConversations?.[firstConversationId]?.messages
12678
+ // )
12679
+ // ) {
12680
+ // setShowChatPlaceholder(false);
12681
+ // } else {
12682
+ // setShowChatPlaceholder(true);
12683
+ // }
12522
12684
  }
12685
+ // setCurrentMode(params?.name?.toLowerCase());
12686
+ // if (firstConversationId) {
12687
+ // setActiveConversationId(firstConversationId);
12688
+ // }
12689
+ // localStorage.setItem(
12690
+ // "currentModeData",
12691
+ // params?.name?.toLowerCase()
12692
+ // );
12693
+ // setNewChatScreen(false);
12694
+ // activeTab.current.activeTab = "agent";
12695
+ // setIsStop(false);
12696
+ // }
12697
+ // setConversation([]);
12698
+ // chatDataInfoRef.current[currentMode] = [];
12523
12699
  },
12524
12700
  icon: jsx(SvgSaveFilterTab, {}),
12525
12701
  },
12526
12702
  ], utilityList: utilityList, isAssistantThinking: false, isCustomScreen: showChatPlaceholder ? showChatPlaceholder : showSavedFilters, customScreenJsx: showChatPlaceholder ?
12527
12703
  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 })
12528
12704
  :
12529
- jsx(ChatbotSaveFilterComponent$1, { savedFilterSets: savedFilterSets }), inputText: userInput, threadList: ["Home"], hideMenuArrow: hideMenu, newChatScreen: newChatScreen, isModuleListLoading: modulesLoading, suggestionBanner: {
12705
+ jsx(ChatbotSaveFilterComponent$1, { savedFilterSets: savedFilterSets, partialClose: partialClose }), inputText: userInput, threadList: ["Home"], hideMenuArrow: hideMenu, newChatScreen: newChatScreen, isModuleListLoading: modulesLoading, suggestionBanner: {
12530
12706
  freeTextHeading: "Try adding more details :",
12531
12707
  freeTextContent: "Alan works better when you provide more context and pointed questions",
12532
12708
  }, isStopIcon: isStop, onStopIconClick: onStopIconClick, footerText: "AI-generated responses may contain errors\u2014please verify important information", showSuggestionBanner: showSavedFilters ? false : showSuggestionBanner, onCloseSuggestionBanner: () => {