impact-chatbot 2.3.61 → 2.3.62

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
@@ -5225,9 +5225,28 @@ const sseevent = (message, messageToStoreRef) => {
5225
5225
  messageToStoreRef.current.navSessionId = parsedData.session_id;
5226
5226
  }
5227
5227
  if (parsedData?.is_error) {
5228
- messageToStoreRef.current.chatData.response =
5229
- messageToStoreRef.current.chatData.response +
5230
- "There is an error, please reach out to IA with this use case.";
5228
+ // Only append the error message once, even if multiple is_error chunks arrive.
5229
+ // Append as a widget item to appendedData so it renders AFTER any existing
5230
+ // widgets (tables, graphs, text widgets) rather than at the top of the response.
5231
+ if (!messageToStoreRef.current.hasErrorMessage) {
5232
+ messageToStoreRef.current.hasErrorMessage = true;
5233
+ const errorMsg = parsedData?.message && parsedData.message !== "[DONE]"
5234
+ ? parsedData.message
5235
+ : "There is an error, please reach out to IA with this use case.";
5236
+ const errorWidget = { type: "text", response: errorMsg };
5237
+ const prevAppended = messageToStoreRef.current.appendedData;
5238
+ if (Array.isArray(prevAppended) && prevAppended.length > 0) {
5239
+ messageToStoreRef.current.appendedData = [...prevAppended, errorWidget];
5240
+ }
5241
+ else if (prevAppended && typeof prevAppended === "object" && Object.keys(prevAppended).length > 0) {
5242
+ messageToStoreRef.current.appendedData = [prevAppended, errorWidget];
5243
+ }
5244
+ else {
5245
+ // No existing widgets — put on chatData.response instead
5246
+ messageToStoreRef.current.chatData.response =
5247
+ messageToStoreRef.current.chatData.response + errorMsg;
5248
+ }
5249
+ }
5231
5250
  // Still process completed/follow-up status even on error chunks
5232
5251
  // so that initValue is set correctly and dummyButton is suppressed
5233
5252
  if (parsedData?.status === "completed" ||
@@ -5712,6 +5731,28 @@ const ButtonContent = ({ bodyText, isFormDisabled = false, isStepFormSubmit = fa
5712
5731
  window.dispatchEvent(new CustomEvent("stepFormStreamEnd"));
5713
5732
  dispatch(smartBotActions.setStepFormStreamData({ status: "error", chunks: chunksRef, sessionId }));
5714
5733
  });
5734
+ // Handle stream closure — fires when the HTTP request completes successfully.
5735
+ // If [DONE] was received, the "message" handler already dispatched status:"done"
5736
+ // and set stepFormStreamControl.isStreaming = false.
5737
+ // If [DONE] was NOT received, the connection closed abruptly mid-processing.
5738
+ sourceRef.current.addEventListener("close", () => {
5739
+ if (stepFormStreamControl.isStreaming) {
5740
+ stepFormStreamControl.isStreaming = false;
5741
+ stepFormStreamControl.abort = null;
5742
+ window.dispatchEvent(new CustomEvent("stepFormStreamEnd"));
5743
+ // Append the abrupt close message as a content chunk so TabularContent
5744
+ // renders it at the bottom (after any already-received widgets/steps)
5745
+ chunksRef.push({
5746
+ status: "content",
5747
+ message: "The requested Task has ended unexpectedly, please retry again",
5748
+ });
5749
+ dispatch(smartBotActions.setStepFormStreamData({
5750
+ status: "error",
5751
+ chunks: [...chunksRef],
5752
+ sessionId,
5753
+ }));
5754
+ }
5755
+ });
5715
5756
  };
5716
5757
  const renderButtons = () => {
5717
5758
  if (!Array.isArray(bodyText.buttons)) {
@@ -8175,6 +8216,26 @@ const StreamedContent = ({ botData }) => {
8175
8216
  }));
8176
8217
  return;
8177
8218
  }
8219
+ // Skip is_error chunks — already handled in AxiosEventSource sseevent()
8220
+ if (data?.is_error) {
8221
+ // Trigger completion if status is "completed"
8222
+ if (data?.status === "completed") {
8223
+ setStepsDone(true);
8224
+ setIsStreamingDone(true);
8225
+ const doneState = streamStateMap.get(streamKey);
8226
+ if (doneState)
8227
+ doneState.completed = true;
8228
+ dispatch(smartBotActions.setMinimizedStreamData({
8229
+ isStreaming: false,
8230
+ stepHeader: questionsRef.current[questionsRef.current.length - 1] || "Completed",
8231
+ stepSubHeader: "Done",
8232
+ stepStatus: "completed",
8233
+ streamStartTime: streamStartTimeRef.current,
8234
+ actionCount: questionsRef.current.length || 1,
8235
+ }));
8236
+ }
8237
+ return;
8238
+ }
8178
8239
  if (data?.message || data?.status === "step" || data?.status === "step_form" || data?.status === "thinking" || data?.status === "questions" || data?.status === "widget") {
8179
8240
  if (data.status === "questions") {
8180
8241
  const incomingQuestions = data.widget_data?.[0]?.questions || [];
@@ -8471,9 +8532,26 @@ const StreamedContent = ({ botData }) => {
8471
8532
  stepRef.current = [...currentSteps];
8472
8533
  setSteps([...currentSteps]);
8473
8534
  }
8474
- // Set the response message for the agent_response tab
8535
+ // Show the abrupt close message at the bottom of any existing content.
8536
+ // If widgets already exist in appendedData, append the error as the last widget
8537
+ // so it renders AFTER the already-received content (not at the top).
8475
8538
  const abruptCloseMessage = "The requested Task has ended unexpectedly, please retry again";
8476
- messageToStoreRef.current.chatData.response = abruptCloseMessage;
8539
+ const hasExistingWidgetsOnErr = messageToStoreRef.current.appendedData &&
8540
+ (isArray(messageToStoreRef.current.appendedData)
8541
+ ? messageToStoreRef.current.appendedData.length > 0
8542
+ : Object.keys(messageToStoreRef.current.appendedData).length > 0);
8543
+ if (hasExistingWidgetsOnErr) {
8544
+ const errorWidget = { type: "text", response: abruptCloseMessage };
8545
+ if (isArray(messageToStoreRef.current.appendedData)) {
8546
+ messageToStoreRef.current.appendedData.push(errorWidget);
8547
+ }
8548
+ else {
8549
+ messageToStoreRef.current.appendedData = [messageToStoreRef.current.appendedData, errorWidget];
8550
+ }
8551
+ }
8552
+ else {
8553
+ messageToStoreRef.current.chatData.response = abruptCloseMessage;
8554
+ }
8477
8555
  setContent(abruptCloseMessage);
8478
8556
  // Dispatch minimized widget data
8479
8557
  dispatch(smartBotActions.setMinimizedStreamData({
@@ -8511,9 +8589,30 @@ const StreamedContent = ({ botData }) => {
8511
8589
  stepRef.current = [...currentSteps];
8512
8590
  setSteps([...currentSteps]);
8513
8591
  }
8514
- // Set the response message for the agent_response tab
8592
+ // Show the abrupt close message. The final response array is structured as:
8593
+ // [textResponseTobeParsed, ...appendedData] — so chatData.response renders FIRST,
8594
+ // then widget items from appendedData render below it.
8595
+ // To ensure the error message appears AFTER already-rendered widgets, we append it
8596
+ // as a text widget item to appendedData instead of setting it on chatData.response.
8515
8597
  const abruptCloseMessage = "The requested Task has ended unexpectedly, please retry again";
8516
- messageToStoreRef.current.chatData.response = abruptCloseMessage;
8598
+ const hasExistingWidgets = messageToStoreRef.current.appendedData &&
8599
+ (isArray(messageToStoreRef.current.appendedData)
8600
+ ? messageToStoreRef.current.appendedData.length > 0
8601
+ : Object.keys(messageToStoreRef.current.appendedData).length > 0);
8602
+ if (hasExistingWidgets) {
8603
+ // Widgets already exist — append error as the last widget so it renders at the bottom
8604
+ const errorWidget = { type: "text", response: abruptCloseMessage };
8605
+ if (isArray(messageToStoreRef.current.appendedData)) {
8606
+ messageToStoreRef.current.appendedData.push(errorWidget);
8607
+ }
8608
+ else {
8609
+ messageToStoreRef.current.appendedData = [messageToStoreRef.current.appendedData, errorWidget];
8610
+ }
8611
+ }
8612
+ else {
8613
+ // No widgets — set on chatData.response (will be the only rendered text)
8614
+ messageToStoreRef.current.chatData.response = abruptCloseMessage;
8615
+ }
8517
8616
  setContent(abruptCloseMessage);
8518
8617
  // Stop thinking if in progress
8519
8618
  if (isThinking) {