@iblai/web-utils 1.7.2 → 1.7.3

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.js CHANGED
@@ -11106,6 +11106,30 @@ const chatSlice = createSlice({
11106
11106
  resetCurrentStreamingMessage: (state) => {
11107
11107
  state.currentStreamingMessage = { id: "", content: "" };
11108
11108
  },
11109
+ updateStreamingMessageId: (state, action) => {
11110
+ const oldId = state.currentStreamingMessage.id;
11111
+ const { newId } = action.payload;
11112
+ if (!newId || oldId === newId) {
11113
+ return;
11114
+ }
11115
+ if (oldId) {
11116
+ const activeMessages = state.chats[state.activeTab];
11117
+ if (activeMessages === null || activeMessages === void 0 ? void 0 : activeMessages.length) {
11118
+ const lastIndex = activeMessages.length - 1;
11119
+ const last = activeMessages[lastIndex];
11120
+ if (last.id === oldId) {
11121
+ state.chats = {
11122
+ ...state.chats,
11123
+ [state.activeTab]: [
11124
+ ...activeMessages.slice(0, lastIndex),
11125
+ { ...last, id: newId },
11126
+ ],
11127
+ };
11128
+ }
11129
+ }
11130
+ }
11131
+ state.currentStreamingMessage.id = newId;
11132
+ },
11109
11133
  setActiveTab: (state, action) => {
11110
11134
  state.activeTab = action.payload;
11111
11135
  },
@@ -12375,7 +12399,7 @@ const useChat = ({ wsUrl, wsToken, flowConfig, sessionId, stopGenerationWsUrl, e
12375
12399
  onStreamingChange === null || onStreamingChange === void 0 ? void 0 : onStreamingChange(false);
12376
12400
  });
12377
12401
  socket.addEventListener("message", (event) => {
12378
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1;
12402
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4;
12379
12403
  if (isWebSocketPaused.current) {
12380
12404
  console.log("[ws-message] Message received but WebSocket is paused");
12381
12405
  return;
@@ -12948,8 +12972,23 @@ const useChat = ({ wsUrl, wsToken, flowConfig, sessionId, stopGenerationWsUrl, e
12948
12972
  onStreamingChange(true);
12949
12973
  return;
12950
12974
  }
12975
+ //HANDLE RECEPTION OF CHAT MESSAGES INFO
12976
+ if ((messageData === null || messageData === void 0 ? void 0 : messageData.type) === "chat_messages" &&
12977
+ ((_t = messageData === null || messageData === void 0 ? void 0 : messageData.messages) === null || _t === void 0 ? void 0 : _t.length) > 0) {
12978
+ const chatMessageID = (_v = (_u = messageData === null || messageData === void 0 ? void 0 : messageData.messages) === null || _u === void 0 ? void 0 : _u.find((pre) => pre.is_ai)) === null || _v === void 0 ? void 0 : _v.id;
12979
+ if (chatMessageID) {
12980
+ dispatch(chatActions.updateStreamingMessageId({ newId: chatMessageID }));
12981
+ currentStreamingMessage.current = {
12982
+ ...currentStreamingMessage.current,
12983
+ id: chatMessageID,
12984
+ };
12985
+ onStreamingMessageUpdate === null || onStreamingMessageUpdate === void 0 ? void 0 : onStreamingMessageUpdate(currentStreamingMessage.current);
12986
+ return;
12987
+ }
12988
+ }
12951
12989
  // Handle streaming message content (chat text)
12952
- if (messageData.data !== undefined || messageData.eos !== undefined) {
12990
+ if ((messageData === null || messageData === void 0 ? void 0 : messageData.type) !== "chat_messages" &&
12991
+ (messageData.data !== undefined || messageData.eos !== undefined)) {
12953
12992
  const messageText = messageData.data || "";
12954
12993
  // If we have content to add, update the in-memory streaming message and Redux
12955
12994
  if (messageText && currentStreamingMessage.current) {
@@ -12965,28 +13004,28 @@ const useChat = ({ wsUrl, wsToken, flowConfig, sessionId, stopGenerationWsUrl, e
12965
13004
  };
12966
13005
  onStreamingMessageUpdate === null || onStreamingMessageUpdate === void 0 ? void 0 : onStreamingMessageUpdate(currentStreamingMessage.current);
12967
13006
  // Update or add message in Redux store
12968
- if ((_t = currentStreamingMessage.current) === null || _t === void 0 ? void 0 : _t.id) {
13007
+ if ((_w = currentStreamingMessage.current) === null || _w === void 0 ? void 0 : _w.id) {
12969
13008
  // TODO: Investigate why `appendMessageToActiveTab` is consuming this action payload
12970
13009
  dispatch(chatActions.appendMessageToActiveTab(undefined));
12971
13010
  }
12972
13011
  }
12973
- // Handle end of stream
12974
13012
  if (messageData.eos) {
13013
+ // Handle end of stream
12975
13014
  const hasPendingArtifact = !!pendingArtifactVersion.current;
12976
- const hasMessageContent = !!((_u = currentStreamingMessage.current) === null || _u === void 0 ? void 0 : _u.content) &&
13015
+ const hasMessageContent = !!((_x = currentStreamingMessage.current) === null || _x === void 0 ? void 0 : _x.content) &&
12977
13016
  currentStreamingMessage.current.content.length > 0;
12978
13017
  console.log("[ws-message] End of stream (EOS) received:", {
12979
- generationId: (_v = currentStreamingMessage.current) === null || _v === void 0 ? void 0 : _v.id,
12980
- finalContentLength: (_x = (_w = currentStreamingMessage.current) === null || _w === void 0 ? void 0 : _w.content) === null || _x === void 0 ? void 0 : _x.length,
12981
- hasContent: !!((_y = currentStreamingMessage.current) === null || _y === void 0 ? void 0 : _y.content),
13018
+ generationId: (_y = currentStreamingMessage.current) === null || _y === void 0 ? void 0 : _y.id,
13019
+ finalContentLength: (_0 = (_z = currentStreamingMessage.current) === null || _z === void 0 ? void 0 : _z.content) === null || _0 === void 0 ? void 0 : _0.length,
13020
+ hasContent: !!((_1 = currentStreamingMessage.current) === null || _1 === void 0 ? void 0 : _1.content),
12982
13021
  hasPendingArtifact,
12983
13022
  });
12984
13023
  // Final update to Redux store with complete message
12985
- if (((_z = currentStreamingMessage.current) === null || _z === void 0 ? void 0 : _z.id) &&
13024
+ if (((_2 = currentStreamingMessage.current) === null || _2 === void 0 ? void 0 : _2.id) &&
12986
13025
  (hasMessageContent || hasPendingArtifact)) {
12987
13026
  console.log("[ws-message] Is currentStreamingMessage.current", {
12988
- id: (_0 = currentStreamingMessage.current) === null || _0 === void 0 ? void 0 : _0.id,
12989
- content: (_1 = currentStreamingMessage.current) === null || _1 === void 0 ? void 0 : _1.content,
13027
+ id: (_3 = currentStreamingMessage.current) === null || _3 === void 0 ? void 0 : _3.id,
13028
+ content: (_4 = currentStreamingMessage.current) === null || _4 === void 0 ? void 0 : _4.content,
12990
13029
  });
12991
13030
  // TODO: Investigate why `appendMessageToActiveTab` is consuming this action payload
12992
13031
  dispatch(chatActions.appendMessageToActiveTab(undefined));
@@ -13041,7 +13080,7 @@ const useChat = ({ wsUrl, wsToken, flowConfig, sessionId, stopGenerationWsUrl, e
13041
13080
  onStatusChange("error");
13042
13081
  }
13043
13082
  });
13044
- socket.addEventListener("error", (error) => {
13083
+ socket.addEventListener("error", () => {
13045
13084
  // Don't show error if we're offline in Tauri - this is expected
13046
13085
  // Check both the ref AND navigator.onLine (the ref may not be updated yet)
13047
13086
  const isLikelyOffline = isOfflineRef.current || (isTauriApp() && !navigator.onLine);
@@ -13710,7 +13749,7 @@ function useAdvancedChat({ tenantKey, mentorId, username = ANONYMOUS_USERNAME, t
13710
13749
  ...result,
13711
13750
  role: result.type === "human" ? "user" : "assistant",
13712
13751
  visible: true,
13713
- id: new Date().getTime(),
13752
+ id: result.id || new Date().getTime(),
13714
13753
  content: typeof result.content === "object" &&
13715
13754
  result.content.length > 0
13716
13755
  ? (_c = result.content.find((item) => item.text)) === null || _c === void 0 ? void 0 : _c.text