@iblai/web-utils 1.7.1 → 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
@@ -9884,9 +9884,8 @@ function TenantProvider({ children, fallback, onAuthSuccess, onAuthFailure, curr
9884
9884
  }
9885
9885
  }
9886
9886
  async function handleLoadTenantMetadata(tenantKey) {
9887
- var _a, _b;
9887
+ var _a;
9888
9888
  setIsLoading(true);
9889
- const MAIN_TENANT_KEY = "main";
9890
9889
  try {
9891
9890
  const data = await fetchTenantMetadata([
9892
9891
  {
@@ -9911,18 +9910,6 @@ function TenantProvider({ children, fallback, onAuthSuccess, onAuthFailure, curr
9911
9910
  const { data: tenants } = await fetchUserTenants();
9912
9911
  const enhancedTenants = await enhanceTenants(tenants, data);
9913
9912
  saveUserTenants(enhancedTenants);
9914
- // If we're in an advertising tenant and user has other tenants,
9915
- // switch to a non-advertising, non-main tenant
9916
- const isCurrentTenantAdvertising = ((_b = data.metadata) === null || _b === void 0 ? void 0 : _b.is_advertising) || isAdvertisingTenant;
9917
- if (isCurrentTenantAdvertising &&
9918
- enhancedTenants &&
9919
- enhancedTenants.length > 0) {
9920
- const nonAdvertisingTenant = enhancedTenants.find((t) => !t.is_advertising && t.key !== MAIN_TENANT_KEY);
9921
- if (nonAdvertisingTenant) {
9922
- handleTenantSwitch(nonAdvertisingTenant.key, false, false);
9923
- return;
9924
- }
9925
- }
9926
9913
  if (currentTenant && currentTenant !== tenantKey) {
9927
9914
  setTenantKey(data.platform_key);
9928
9915
  const userAlreadyInTenant = enhancedTenants === null || enhancedTenants === void 0 ? void 0 : enhancedTenants.find((t) => t.key === tenantKey);
@@ -11119,6 +11106,30 @@ const chatSlice = createSlice({
11119
11106
  resetCurrentStreamingMessage: (state) => {
11120
11107
  state.currentStreamingMessage = { id: "", content: "" };
11121
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
+ },
11122
11133
  setActiveTab: (state, action) => {
11123
11134
  state.activeTab = action.payload;
11124
11135
  },
@@ -12388,7 +12399,7 @@ const useChat = ({ wsUrl, wsToken, flowConfig, sessionId, stopGenerationWsUrl, e
12388
12399
  onStreamingChange === null || onStreamingChange === void 0 ? void 0 : onStreamingChange(false);
12389
12400
  });
12390
12401
  socket.addEventListener("message", (event) => {
12391
- 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;
12392
12403
  if (isWebSocketPaused.current) {
12393
12404
  console.log("[ws-message] Message received but WebSocket is paused");
12394
12405
  return;
@@ -12961,8 +12972,23 @@ const useChat = ({ wsUrl, wsToken, flowConfig, sessionId, stopGenerationWsUrl, e
12961
12972
  onStreamingChange(true);
12962
12973
  return;
12963
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
+ }
12964
12989
  // Handle streaming message content (chat text)
12965
- 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)) {
12966
12992
  const messageText = messageData.data || "";
12967
12993
  // If we have content to add, update the in-memory streaming message and Redux
12968
12994
  if (messageText && currentStreamingMessage.current) {
@@ -12978,28 +13004,28 @@ const useChat = ({ wsUrl, wsToken, flowConfig, sessionId, stopGenerationWsUrl, e
12978
13004
  };
12979
13005
  onStreamingMessageUpdate === null || onStreamingMessageUpdate === void 0 ? void 0 : onStreamingMessageUpdate(currentStreamingMessage.current);
12980
13006
  // Update or add message in Redux store
12981
- 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) {
12982
13008
  // TODO: Investigate why `appendMessageToActiveTab` is consuming this action payload
12983
13009
  dispatch(chatActions.appendMessageToActiveTab(undefined));
12984
13010
  }
12985
13011
  }
12986
- // Handle end of stream
12987
13012
  if (messageData.eos) {
13013
+ // Handle end of stream
12988
13014
  const hasPendingArtifact = !!pendingArtifactVersion.current;
12989
- 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) &&
12990
13016
  currentStreamingMessage.current.content.length > 0;
12991
13017
  console.log("[ws-message] End of stream (EOS) received:", {
12992
- generationId: (_v = currentStreamingMessage.current) === null || _v === void 0 ? void 0 : _v.id,
12993
- finalContentLength: (_x = (_w = currentStreamingMessage.current) === null || _w === void 0 ? void 0 : _w.content) === null || _x === void 0 ? void 0 : _x.length,
12994
- 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),
12995
13021
  hasPendingArtifact,
12996
13022
  });
12997
13023
  // Final update to Redux store with complete message
12998
- 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) &&
12999
13025
  (hasMessageContent || hasPendingArtifact)) {
13000
13026
  console.log("[ws-message] Is currentStreamingMessage.current", {
13001
- id: (_0 = currentStreamingMessage.current) === null || _0 === void 0 ? void 0 : _0.id,
13002
- 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,
13003
13029
  });
13004
13030
  // TODO: Investigate why `appendMessageToActiveTab` is consuming this action payload
13005
13031
  dispatch(chatActions.appendMessageToActiveTab(undefined));
@@ -13054,7 +13080,7 @@ const useChat = ({ wsUrl, wsToken, flowConfig, sessionId, stopGenerationWsUrl, e
13054
13080
  onStatusChange("error");
13055
13081
  }
13056
13082
  });
13057
- socket.addEventListener("error", (error) => {
13083
+ socket.addEventListener("error", () => {
13058
13084
  // Don't show error if we're offline in Tauri - this is expected
13059
13085
  // Check both the ref AND navigator.onLine (the ref may not be updated yet)
13060
13086
  const isLikelyOffline = isOfflineRef.current || (isTauriApp() && !navigator.onLine);
@@ -13723,7 +13749,7 @@ function useAdvancedChat({ tenantKey, mentorId, username = ANONYMOUS_USERNAME, t
13723
13749
  ...result,
13724
13750
  role: result.type === "human" ? "user" : "assistant",
13725
13751
  visible: true,
13726
- id: new Date().getTime(),
13752
+ id: result.id || new Date().getTime(),
13727
13753
  content: typeof result.content === "object" &&
13728
13754
  result.content.length > 0
13729
13755
  ? (_c = result.content.find((item) => item.text)) === null || _c === void 0 ? void 0 : _c.text