impact-chatbot 2.3.49 → 2.3.50

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.cjs.js CHANGED
@@ -5496,6 +5496,15 @@ const ButtonContent = ({ bodyText, isFormDisabled = false, isStepFormSubmit = fa
5496
5496
  try {
5497
5497
  const data = JSON.parse(event.data);
5498
5498
  console.log("[ButtonContent] SSE chunk:", data);
5499
+ // Always keep stepFormStreamControl.sessionId in sync with the latest chunk's session_id
5500
+ if (data?.session_id) {
5501
+ stepFormStreamControl.sessionId = data.session_id;
5502
+ sessionStorage.setItem("stepForm_sessionId", data.session_id);
5503
+ }
5504
+ if (data?.chat_id) {
5505
+ stepFormStreamControl.chatId = data.chat_id;
5506
+ sessionStorage.setItem("stepForm_chatId", data.chat_id);
5507
+ }
5499
5508
  if (data?.status === "step" || data?.status === "step_form" || data?.status === "questions" || data?.status === "thinking" || data?.status === "widget") {
5500
5509
  chunksRef.push(data);
5501
5510
  // Dispatch widget chunks immediately for real-time rendering
@@ -5520,6 +5529,8 @@ const ButtonContent = ({ bodyText, isFormDisabled = false, isStepFormSubmit = fa
5520
5529
  stepFormStreamControl.initValue = true;
5521
5530
  stepFormStreamControl.sessionId = "";
5522
5531
  stepFormStreamControl.uniqueChatId = data?.chat_id ? data.chat_id : "";
5532
+ // Clear sessionStorage so stale session_id isn't picked up by future non-init calls
5533
+ sessionStorage.setItem("stepForm_sessionId", "");
5523
5534
  }
5524
5535
  // Stream ended — dispatch all collected chunks at once
5525
5536
  stepFormStreamControl.isStreaming = false;
@@ -7068,6 +7079,7 @@ const StreamedContent = ({ botData }) => {
7068
7079
  const thinkingDoneRef = React.useRef(false);
7069
7080
  const setThinkingContentRef = React.useRef(setThinkingContent); // Store current setThinkingContent function
7070
7081
  const streamTimeoutRef = React.useRef(null); // Ref for stream timeout
7082
+ const streamingDoneProcessedRef = React.useRef(false); // Guard to prevent isStreamingDone effect running twice
7071
7083
  // Stable key for the module-level streamStateMap (survives cloneDeep of botData)
7072
7084
  const streamKey = React.useRef(`${currentMode}_${activeConversationId}_${JSON.stringify(botData.inputBody)}`).current;
7073
7085
  // Look up existing stream state from the Map (persists across tab-switch remounts)
@@ -7500,7 +7512,8 @@ const StreamedContent = ({ botData }) => {
7500
7512
  * Parses the accumulated response and updates the chat history
7501
7513
  */
7502
7514
  React.useEffect(() => {
7503
- if (isStreamingDone) {
7515
+ if (isStreamingDone && !streamingDoneProcessedRef.current) {
7516
+ streamingDoneProcessedRef.current = true;
7504
7517
  localStorage.setItem("isStreaming", "false");
7505
7518
  if (currentMode === "agent") {
7506
7519
  setIsStop(false);
@@ -12599,7 +12612,7 @@ const SmartBot = (props) => {
12599
12612
  let data = {
12600
12613
  agentId: currentAgentId,
12601
12614
  userInput: lodash.cloneDeep(userInput),
12602
- sessionId: currentSessionId,
12615
+ sessionId: lodash.isEmpty(userInput) ? currentSessionId : "",
12603
12616
  baseUrl: baseUrl,
12604
12617
  userExplicitInput: userExplicitInput,
12605
12618
  textWithColumnNames: textWithColumnNames,
@@ -12637,6 +12650,13 @@ const SmartBot = (props) => {
12637
12650
  // Reset step form stream state so old TabularContent instances don't process new data
12638
12651
  dispatch(smartBotActions.setStepFormStreamData(null));
12639
12652
  resetActiveTabularInstance();
12653
+ // Reset stepFormStreamControl so stale session_id doesn't leak into new prompts
12654
+ stepFormStreamControl.sessionId = "";
12655
+ stepFormStreamControl.chatId = "";
12656
+ stepFormStreamControl.initValue = false;
12657
+ stepFormStreamControl.uniqueChatId = "";
12658
+ sessionStorage.removeItem("stepForm_sessionId");
12659
+ sessionStorage.removeItem("stepForm_chatId");
12640
12660
  // dispatch(setChatbotContext({}));
12641
12661
  setUserInput(params?.text);
12642
12662
  handleSendMessage(params?.text, params?.userExplicitInput, params?.textWithColumnNames);