@iblai/web-utils 1.7.2 → 1.8.0
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/data-layer/src/features/chat/constants.d.ts +8 -0
- package/dist/data-layer/src/features/chat/custom-api-slice.d.ts +272 -0
- package/dist/data-layer/src/index.d.ts +1 -0
- package/dist/index.d.ts +9 -2
- package/dist/index.esm.js +60 -18
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +60 -18
- package/dist/index.js.map +1 -1
- package/dist/package.json +1 -1
- package/dist/web-utils/src/hooks/chat/use-chat-v2.d.ts +6 -0
- package/dist/web-utils/src/utils/auth.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1181,17 +1181,19 @@ async function redirectToAuthSpa(options) {
|
|
|
1181
1181
|
logoutTimestamp: "ibl_logout_timestamp",
|
|
1182
1182
|
loginTimestamp: "ibl_login_timestamp",
|
|
1183
1183
|
tenantSwitching: "ibl_tenant_switching",
|
|
1184
|
-
}, hasNonExpiredAuthToken, isOffline, preserveTokenKey, authRedirectProxy, isNativeApp, } = options;
|
|
1185
|
-
console.log("[redirectToAuthSpa] starting redirect to auth spa", redirectTo, platformKey, logout, saveRedirect);
|
|
1184
|
+
}, hasNonExpiredAuthToken, isOffline, preserveTokenKey, authRedirectProxy, isNativeApp, forceRedirect = false, } = options;
|
|
1185
|
+
console.log("[redirectToAuthSpa] starting redirect to auth spa", redirectTo, platformKey, logout, saveRedirect, forceRedirect);
|
|
1186
1186
|
// Skip if a tenant switch is already in progress
|
|
1187
|
-
if (
|
|
1187
|
+
if (!forceRedirect &&
|
|
1188
|
+
cookieNames.tenantSwitching &&
|
|
1188
1189
|
document.cookie.includes(cookieNames.tenantSwitching)) {
|
|
1189
1190
|
console.log("[redirectToAuthSpa] Tenant switch in progress, skipping redirect");
|
|
1190
1191
|
return;
|
|
1191
1192
|
}
|
|
1192
1193
|
// Skip if a login occurred after the last logout (login takes precedence)
|
|
1193
1194
|
// but only if this app actually has a valid auth token
|
|
1194
|
-
if (
|
|
1195
|
+
if (!forceRedirect &&
|
|
1196
|
+
hasNonExpiredAuthToken &&
|
|
1195
1197
|
cookieNames.loginTimestamp &&
|
|
1196
1198
|
cookieNames.logoutTimestamp) {
|
|
1197
1199
|
const loginTs = getCookieValue(cookieNames.loginTimestamp);
|
|
@@ -1203,7 +1205,8 @@ async function redirectToAuthSpa(options) {
|
|
|
1203
1205
|
hasValidToken,
|
|
1204
1206
|
loginAhead: loginTs && logoutTs ? Number(loginTs) > Number(logoutTs) : false,
|
|
1205
1207
|
});
|
|
1206
|
-
if (
|
|
1208
|
+
if (!forceRedirect &&
|
|
1209
|
+
hasValidToken &&
|
|
1207
1210
|
loginTs &&
|
|
1208
1211
|
logoutTs &&
|
|
1209
1212
|
Number(loginTs) > Number(logoutTs)) {
|
|
@@ -11106,6 +11109,30 @@ const chatSlice = createSlice({
|
|
|
11106
11109
|
resetCurrentStreamingMessage: (state) => {
|
|
11107
11110
|
state.currentStreamingMessage = { id: "", content: "" };
|
|
11108
11111
|
},
|
|
11112
|
+
updateStreamingMessageId: (state, action) => {
|
|
11113
|
+
const oldId = state.currentStreamingMessage.id;
|
|
11114
|
+
const { newId } = action.payload;
|
|
11115
|
+
if (!newId || oldId === newId) {
|
|
11116
|
+
return;
|
|
11117
|
+
}
|
|
11118
|
+
if (oldId) {
|
|
11119
|
+
const activeMessages = state.chats[state.activeTab];
|
|
11120
|
+
if (activeMessages === null || activeMessages === void 0 ? void 0 : activeMessages.length) {
|
|
11121
|
+
const lastIndex = activeMessages.length - 1;
|
|
11122
|
+
const last = activeMessages[lastIndex];
|
|
11123
|
+
if (last.id === oldId) {
|
|
11124
|
+
state.chats = {
|
|
11125
|
+
...state.chats,
|
|
11126
|
+
[state.activeTab]: [
|
|
11127
|
+
...activeMessages.slice(0, lastIndex),
|
|
11128
|
+
{ ...last, id: newId },
|
|
11129
|
+
],
|
|
11130
|
+
};
|
|
11131
|
+
}
|
|
11132
|
+
}
|
|
11133
|
+
}
|
|
11134
|
+
state.currentStreamingMessage.id = newId;
|
|
11135
|
+
},
|
|
11109
11136
|
setActiveTab: (state, action) => {
|
|
11110
11137
|
state.activeTab = action.payload;
|
|
11111
11138
|
},
|
|
@@ -12375,7 +12402,7 @@ const useChat = ({ wsUrl, wsToken, flowConfig, sessionId, stopGenerationWsUrl, e
|
|
|
12375
12402
|
onStreamingChange === null || onStreamingChange === void 0 ? void 0 : onStreamingChange(false);
|
|
12376
12403
|
});
|
|
12377
12404
|
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;
|
|
12405
|
+
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
12406
|
if (isWebSocketPaused.current) {
|
|
12380
12407
|
console.log("[ws-message] Message received but WebSocket is paused");
|
|
12381
12408
|
return;
|
|
@@ -12948,8 +12975,23 @@ const useChat = ({ wsUrl, wsToken, flowConfig, sessionId, stopGenerationWsUrl, e
|
|
|
12948
12975
|
onStreamingChange(true);
|
|
12949
12976
|
return;
|
|
12950
12977
|
}
|
|
12978
|
+
//HANDLE RECEPTION OF CHAT MESSAGES INFO
|
|
12979
|
+
if ((messageData === null || messageData === void 0 ? void 0 : messageData.type) === "chat_messages" &&
|
|
12980
|
+
((_t = messageData === null || messageData === void 0 ? void 0 : messageData.messages) === null || _t === void 0 ? void 0 : _t.length) > 0) {
|
|
12981
|
+
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;
|
|
12982
|
+
if (chatMessageID) {
|
|
12983
|
+
dispatch(chatActions.updateStreamingMessageId({ newId: chatMessageID }));
|
|
12984
|
+
currentStreamingMessage.current = {
|
|
12985
|
+
...currentStreamingMessage.current,
|
|
12986
|
+
id: chatMessageID,
|
|
12987
|
+
};
|
|
12988
|
+
onStreamingMessageUpdate === null || onStreamingMessageUpdate === void 0 ? void 0 : onStreamingMessageUpdate(currentStreamingMessage.current);
|
|
12989
|
+
return;
|
|
12990
|
+
}
|
|
12991
|
+
}
|
|
12951
12992
|
// Handle streaming message content (chat text)
|
|
12952
|
-
if (messageData
|
|
12993
|
+
if ((messageData === null || messageData === void 0 ? void 0 : messageData.type) !== "chat_messages" &&
|
|
12994
|
+
(messageData.data !== undefined || messageData.eos !== undefined)) {
|
|
12953
12995
|
const messageText = messageData.data || "";
|
|
12954
12996
|
// If we have content to add, update the in-memory streaming message and Redux
|
|
12955
12997
|
if (messageText && currentStreamingMessage.current) {
|
|
@@ -12965,28 +13007,28 @@ const useChat = ({ wsUrl, wsToken, flowConfig, sessionId, stopGenerationWsUrl, e
|
|
|
12965
13007
|
};
|
|
12966
13008
|
onStreamingMessageUpdate === null || onStreamingMessageUpdate === void 0 ? void 0 : onStreamingMessageUpdate(currentStreamingMessage.current);
|
|
12967
13009
|
// Update or add message in Redux store
|
|
12968
|
-
if ((
|
|
13010
|
+
if ((_w = currentStreamingMessage.current) === null || _w === void 0 ? void 0 : _w.id) {
|
|
12969
13011
|
// TODO: Investigate why `appendMessageToActiveTab` is consuming this action payload
|
|
12970
13012
|
dispatch(chatActions.appendMessageToActiveTab(undefined));
|
|
12971
13013
|
}
|
|
12972
13014
|
}
|
|
12973
|
-
// Handle end of stream
|
|
12974
13015
|
if (messageData.eos) {
|
|
13016
|
+
// Handle end of stream
|
|
12975
13017
|
const hasPendingArtifact = !!pendingArtifactVersion.current;
|
|
12976
|
-
const hasMessageContent = !!((
|
|
13018
|
+
const hasMessageContent = !!((_x = currentStreamingMessage.current) === null || _x === void 0 ? void 0 : _x.content) &&
|
|
12977
13019
|
currentStreamingMessage.current.content.length > 0;
|
|
12978
13020
|
console.log("[ws-message] End of stream (EOS) received:", {
|
|
12979
|
-
generationId: (
|
|
12980
|
-
finalContentLength: (
|
|
12981
|
-
hasContent: !!((
|
|
13021
|
+
generationId: (_y = currentStreamingMessage.current) === null || _y === void 0 ? void 0 : _y.id,
|
|
13022
|
+
finalContentLength: (_0 = (_z = currentStreamingMessage.current) === null || _z === void 0 ? void 0 : _z.content) === null || _0 === void 0 ? void 0 : _0.length,
|
|
13023
|
+
hasContent: !!((_1 = currentStreamingMessage.current) === null || _1 === void 0 ? void 0 : _1.content),
|
|
12982
13024
|
hasPendingArtifact,
|
|
12983
13025
|
});
|
|
12984
13026
|
// Final update to Redux store with complete message
|
|
12985
|
-
if (((
|
|
13027
|
+
if (((_2 = currentStreamingMessage.current) === null || _2 === void 0 ? void 0 : _2.id) &&
|
|
12986
13028
|
(hasMessageContent || hasPendingArtifact)) {
|
|
12987
13029
|
console.log("[ws-message] Is currentStreamingMessage.current", {
|
|
12988
|
-
id: (
|
|
12989
|
-
content: (
|
|
13030
|
+
id: (_3 = currentStreamingMessage.current) === null || _3 === void 0 ? void 0 : _3.id,
|
|
13031
|
+
content: (_4 = currentStreamingMessage.current) === null || _4 === void 0 ? void 0 : _4.content,
|
|
12990
13032
|
});
|
|
12991
13033
|
// TODO: Investigate why `appendMessageToActiveTab` is consuming this action payload
|
|
12992
13034
|
dispatch(chatActions.appendMessageToActiveTab(undefined));
|
|
@@ -13041,7 +13083,7 @@ const useChat = ({ wsUrl, wsToken, flowConfig, sessionId, stopGenerationWsUrl, e
|
|
|
13041
13083
|
onStatusChange("error");
|
|
13042
13084
|
}
|
|
13043
13085
|
});
|
|
13044
|
-
socket.addEventListener("error", (
|
|
13086
|
+
socket.addEventListener("error", () => {
|
|
13045
13087
|
// Don't show error if we're offline in Tauri - this is expected
|
|
13046
13088
|
// Check both the ref AND navigator.onLine (the ref may not be updated yet)
|
|
13047
13089
|
const isLikelyOffline = isOfflineRef.current || (isTauriApp() && !navigator.onLine);
|
|
@@ -13710,7 +13752,7 @@ function useAdvancedChat({ tenantKey, mentorId, username = ANONYMOUS_USERNAME, t
|
|
|
13710
13752
|
...result,
|
|
13711
13753
|
role: result.type === "human" ? "user" : "assistant",
|
|
13712
13754
|
visible: true,
|
|
13713
|
-
id: new Date().getTime(),
|
|
13755
|
+
id: result.id || new Date().getTime(),
|
|
13714
13756
|
content: typeof result.content === "object" &&
|
|
13715
13757
|
result.content.length > 0
|
|
13716
13758
|
? (_c = result.content.find((item) => item.text)) === null || _c === void 0 ? void 0 : _c.text
|