@iblai/web-utils 1.1.10 → 1.1.11
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 +15 -2
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +15 -2
- package/dist/index.js.map +1 -1
- package/dist/package.json +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6974,6 +6974,10 @@ const useChat = ({ wsUrl, wsToken, flowConfig, sessionId, stopGenerationWsUrl, e
|
|
|
6974
6974
|
const ws = React.useRef(null);
|
|
6975
6975
|
const isConnected = React.useRef(false);
|
|
6976
6976
|
const messageQueue = React.useRef([]);
|
|
6977
|
+
// Keep sessionId in a ref so sendMessage always reads the latest value,
|
|
6978
|
+
// avoiding stale closures when Redux updates sessionIds between renders.
|
|
6979
|
+
const sessionIdRef = React.useRef(sessionId);
|
|
6980
|
+
sessionIdRef.current = sessionId;
|
|
6977
6981
|
const currentStreamingMessage = React.useRef({
|
|
6978
6982
|
id: null,
|
|
6979
6983
|
content: "",
|
|
@@ -7914,9 +7918,19 @@ const useChat = ({ wsUrl, wsToken, flowConfig, sessionId, stopGenerationWsUrl, e
|
|
|
7914
7918
|
onStatusChange("error");
|
|
7915
7919
|
return;
|
|
7916
7920
|
}
|
|
7921
|
+
// Guard against sending messages without a session ID.
|
|
7922
|
+
// This can happen due to race conditions (e.g., user sends before
|
|
7923
|
+
// createSessionId API returns, or stale closure after tab change).
|
|
7924
|
+
const currentSessionId = sessionIdRef.current;
|
|
7925
|
+
if (!currentSessionId) {
|
|
7926
|
+
console.warn("[sendMessage] No session ID available, cannot send message");
|
|
7927
|
+
onStatusChange("error");
|
|
7928
|
+
errorHandler === null || errorHandler === void 0 ? void 0 : errorHandler("Chat session not ready. Please try again.");
|
|
7929
|
+
return;
|
|
7930
|
+
}
|
|
7917
7931
|
let messageData = {
|
|
7918
7932
|
flow: flowConfig,
|
|
7919
|
-
session_id:
|
|
7933
|
+
session_id: currentSessionId,
|
|
7920
7934
|
token: wsToken,
|
|
7921
7935
|
prompt: text || "", // Allow empty prompt when sending files
|
|
7922
7936
|
};
|
|
@@ -7989,7 +8003,6 @@ const useChat = ({ wsUrl, wsToken, flowConfig, sessionId, stopGenerationWsUrl, e
|
|
|
7989
8003
|
}
|
|
7990
8004
|
}, [
|
|
7991
8005
|
flowConfig,
|
|
7992
|
-
sessionId,
|
|
7993
8006
|
wsToken,
|
|
7994
8007
|
store,
|
|
7995
8008
|
triggerHapticFeedback,
|