@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.esm.js
CHANGED
|
@@ -6954,6 +6954,10 @@ const useChat = ({ wsUrl, wsToken, flowConfig, sessionId, stopGenerationWsUrl, e
|
|
|
6954
6954
|
const ws = useRef(null);
|
|
6955
6955
|
const isConnected = useRef(false);
|
|
6956
6956
|
const messageQueue = useRef([]);
|
|
6957
|
+
// Keep sessionId in a ref so sendMessage always reads the latest value,
|
|
6958
|
+
// avoiding stale closures when Redux updates sessionIds between renders.
|
|
6959
|
+
const sessionIdRef = useRef(sessionId);
|
|
6960
|
+
sessionIdRef.current = sessionId;
|
|
6957
6961
|
const currentStreamingMessage = useRef({
|
|
6958
6962
|
id: null,
|
|
6959
6963
|
content: "",
|
|
@@ -7894,9 +7898,19 @@ const useChat = ({ wsUrl, wsToken, flowConfig, sessionId, stopGenerationWsUrl, e
|
|
|
7894
7898
|
onStatusChange("error");
|
|
7895
7899
|
return;
|
|
7896
7900
|
}
|
|
7901
|
+
// Guard against sending messages without a session ID.
|
|
7902
|
+
// This can happen due to race conditions (e.g., user sends before
|
|
7903
|
+
// createSessionId API returns, or stale closure after tab change).
|
|
7904
|
+
const currentSessionId = sessionIdRef.current;
|
|
7905
|
+
if (!currentSessionId) {
|
|
7906
|
+
console.warn("[sendMessage] No session ID available, cannot send message");
|
|
7907
|
+
onStatusChange("error");
|
|
7908
|
+
errorHandler === null || errorHandler === void 0 ? void 0 : errorHandler("Chat session not ready. Please try again.");
|
|
7909
|
+
return;
|
|
7910
|
+
}
|
|
7897
7911
|
let messageData = {
|
|
7898
7912
|
flow: flowConfig,
|
|
7899
|
-
session_id:
|
|
7913
|
+
session_id: currentSessionId,
|
|
7900
7914
|
token: wsToken,
|
|
7901
7915
|
prompt: text || "", // Allow empty prompt when sending files
|
|
7902
7916
|
};
|
|
@@ -7969,7 +7983,6 @@ const useChat = ({ wsUrl, wsToken, flowConfig, sessionId, stopGenerationWsUrl, e
|
|
|
7969
7983
|
}
|
|
7970
7984
|
}, [
|
|
7971
7985
|
flowConfig,
|
|
7972
|
-
sessionId,
|
|
7973
7986
|
wsToken,
|
|
7974
7987
|
store,
|
|
7975
7988
|
triggerHapticFeedback,
|