@iblai/web-utils 1.1.9 → 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/data-layer/src/features/analytics/custom-api-slice.d.ts +311 -0
- package/dist/data-layer/src/index.d.ts +1 -0
- package/dist/index.d.ts +9 -7
- package/dist/index.esm.js +76 -47
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +76 -47
- package/dist/index.js.map +1 -1
- package/dist/package.json +1 -1
- package/dist/web-utils/src/hooks/chat/use-advanced-chat.d.ts +2 -1
- package/dist/web-utils/src/hooks/chat/use-mentor-tools.d.ts +2 -1
- package/dist/web-utils/src/hooks/use-mentor-settings.d.ts +2 -1
- package/package.json +1 -1
- package/dist/web-utils/tsconfig.tsbuildinfo +0 -1
package/dist/index.js
CHANGED
|
@@ -3439,6 +3439,13 @@ function TenantProvider({ children, fallback, onAuthSuccess, onAuthFailure, curr
|
|
|
3439
3439
|
// user is not authenticated so we don't need to do anything that concerns an authenticated user
|
|
3440
3440
|
return;
|
|
3441
3441
|
}
|
|
3442
|
+
// Logged-in user on a public route (e.g. shareable link) visiting another tenant
|
|
3443
|
+
// — treat as visitor, skip tenant join/token/RBAC calls that will 403
|
|
3444
|
+
if (userIsAccessingPublicRoute) {
|
|
3445
|
+
saveVisitingTenant === null || saveVisitingTenant === void 0 ? void 0 : saveVisitingTenant(newCurrentTenant);
|
|
3446
|
+
setIsLoading(false);
|
|
3447
|
+
return;
|
|
3448
|
+
}
|
|
3442
3449
|
const { data: tenants } = await fetchUserTenants();
|
|
3443
3450
|
const enhancedTenants = await enhanceTenants(tenants, data);
|
|
3444
3451
|
saveUserTenants(enhancedTenants);
|
|
@@ -3456,10 +3463,10 @@ function TenantProvider({ children, fallback, onAuthSuccess, onAuthFailure, curr
|
|
|
3456
3463
|
}
|
|
3457
3464
|
if (currentTenant && currentTenant !== tenantKey) {
|
|
3458
3465
|
setTenantKey(data.platform_key);
|
|
3459
|
-
const rbacPermissions = await loadPlatformPermissions(data.platform_key);
|
|
3460
|
-
onLoadPlatformPermissions === null || onLoadPlatformPermissions === void 0 ? void 0 : onLoadPlatformPermissions(rbacPermissions);
|
|
3461
3466
|
const userAlreadyInTenant = enhancedTenants === null || enhancedTenants === void 0 ? void 0 : enhancedTenants.find((t) => t.key === tenantKey);
|
|
3462
3467
|
if (userAlreadyInTenant) {
|
|
3468
|
+
const rbacPermissions = await loadPlatformPermissions(data.platform_key);
|
|
3469
|
+
onLoadPlatformPermissions === null || onLoadPlatformPermissions === void 0 ? void 0 : onLoadPlatformPermissions(rbacPermissions);
|
|
3463
3470
|
const formData = new FormData();
|
|
3464
3471
|
formData.append("platform_key", tenantKey);
|
|
3465
3472
|
const { data: tokenResponse } = await getAppToken(formData).unwrap();
|
|
@@ -3490,6 +3497,8 @@ function TenantProvider({ children, fallback, onAuthSuccess, onAuthFailure, curr
|
|
|
3490
3497
|
else {
|
|
3491
3498
|
// TODO: What happense when if for any reason we fetch tenants and it's an empty list
|
|
3492
3499
|
}
|
|
3500
|
+
const rbacPermissions = await loadPlatformPermissions(data.platform_key);
|
|
3501
|
+
onLoadPlatformPermissions === null || onLoadPlatformPermissions === void 0 ? void 0 : onLoadPlatformPermissions(rbacPermissions);
|
|
3493
3502
|
onAutoJoinUserToTenant === null || onAutoJoinUserToTenant === void 0 ? void 0 : onAutoJoinUserToTenant((_c = data.platform_name) !== null && _c !== void 0 ? _c : data === null || data === void 0 ? void 0 : data.platform_key.toUpperCase());
|
|
3494
3503
|
saveTenant === null || saveTenant === void 0 ? void 0 : saveTenant(tenantKey);
|
|
3495
3504
|
setUserIsAccessingPublicRoute(false);
|
|
@@ -3961,7 +3970,7 @@ function MentorProvider({ children, fallback, onAuthSuccess, onAuthFailure, redi
|
|
|
3961
3970
|
mentorDbId = await getMentorDbId(mentor);
|
|
3962
3971
|
}
|
|
3963
3972
|
// Load permissions if we have a mentor DB ID and user is logged in
|
|
3964
|
-
if (mentorDbId && isLoggedIn) {
|
|
3973
|
+
if (mentorDbId && isLoggedIn && !userIsAccessingPublicRoute) {
|
|
3965
3974
|
const rbacPermissions = await loadMentorsPermissions(mentorDbId);
|
|
3966
3975
|
onLoadMentorsPermissions === null || onLoadMentorsPermissions === void 0 ? void 0 : onLoadMentorsPermissions(rbacPermissions);
|
|
3967
3976
|
}
|
|
@@ -4008,7 +4017,9 @@ function MentorProvider({ children, fallback, onAuthSuccess, onAuthFailure, redi
|
|
|
4008
4017
|
}
|
|
4009
4018
|
else {
|
|
4010
4019
|
console.log("requested mentor exists in tenant, proceeding", requestedMentorId);
|
|
4011
|
-
if (requestedMentorDbId &&
|
|
4020
|
+
if (requestedMentorDbId &&
|
|
4021
|
+
isLoggedIn &&
|
|
4022
|
+
!userIsAccessingPublicRoute) {
|
|
4012
4023
|
const rbacPermissions = await loadMentorsPermissions(requestedMentorDbId);
|
|
4013
4024
|
onLoadMentorsPermissions === null || onLoadMentorsPermissions === void 0 ? void 0 : onLoadMentorsPermissions(rbacPermissions);
|
|
4014
4025
|
}
|
|
@@ -6963,6 +6974,10 @@ const useChat = ({ wsUrl, wsToken, flowConfig, sessionId, stopGenerationWsUrl, e
|
|
|
6963
6974
|
const ws = React.useRef(null);
|
|
6964
6975
|
const isConnected = React.useRef(false);
|
|
6965
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;
|
|
6966
6981
|
const currentStreamingMessage = React.useRef({
|
|
6967
6982
|
id: null,
|
|
6968
6983
|
content: "",
|
|
@@ -7903,9 +7918,19 @@ const useChat = ({ wsUrl, wsToken, flowConfig, sessionId, stopGenerationWsUrl, e
|
|
|
7903
7918
|
onStatusChange("error");
|
|
7904
7919
|
return;
|
|
7905
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
|
+
}
|
|
7906
7931
|
let messageData = {
|
|
7907
7932
|
flow: flowConfig,
|
|
7908
|
-
session_id:
|
|
7933
|
+
session_id: currentSessionId,
|
|
7909
7934
|
token: wsToken,
|
|
7910
7935
|
prompt: text || "", // Allow empty prompt when sending files
|
|
7911
7936
|
};
|
|
@@ -7978,7 +8003,6 @@ const useChat = ({ wsUrl, wsToken, flowConfig, sessionId, stopGenerationWsUrl, e
|
|
|
7978
8003
|
}
|
|
7979
8004
|
}, [
|
|
7980
8005
|
flowConfig,
|
|
7981
|
-
sessionId,
|
|
7982
8006
|
wsToken,
|
|
7983
8007
|
store,
|
|
7984
8008
|
triggerHapticFeedback,
|
|
@@ -15548,6 +15572,24 @@ createApi({
|
|
|
15548
15572
|
}),
|
|
15549
15573
|
});
|
|
15550
15574
|
|
|
15575
|
+
createApi({
|
|
15576
|
+
reducerPath: 'analyticsCustomApiSlice',
|
|
15577
|
+
baseQuery: iblFetchBaseQuery,
|
|
15578
|
+
tagTypes: ['Analytics'],
|
|
15579
|
+
endpoints: (builder) => ({
|
|
15580
|
+
getDownloadReportFromURL: builder.query({
|
|
15581
|
+
query: ({ url }) => ({
|
|
15582
|
+
url: url,
|
|
15583
|
+
service: SERVICES.DM,
|
|
15584
|
+
method: 'GET',
|
|
15585
|
+
responseHandler: (response) => response.blob(),
|
|
15586
|
+
}),
|
|
15587
|
+
// Blobs are non-serializable; disable caching to prevent Redux serialization warnings
|
|
15588
|
+
keepUnusedDataFor: 0,
|
|
15589
|
+
}),
|
|
15590
|
+
}),
|
|
15591
|
+
});
|
|
15592
|
+
|
|
15551
15593
|
createApi({
|
|
15552
15594
|
reducerPath: 'reportsApiSlice',
|
|
15553
15595
|
baseQuery: iblFakeBaseQuery,
|
|
@@ -17338,8 +17380,8 @@ createApi({
|
|
|
17338
17380
|
}),
|
|
17339
17381
|
});
|
|
17340
17382
|
|
|
17341
|
-
function useMentorSettings({ mentorId, tenantKey, username, }) {
|
|
17342
|
-
var _a, _b, _c, _d;
|
|
17383
|
+
function useMentorSettings({ mentorId, tenantKey, username, isPublicRoute, }) {
|
|
17384
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
17343
17385
|
const isLoggedIn = username !== ANONYMOUS_USERNAME;
|
|
17344
17386
|
const { data: mentorSettings } = useGetMentorSettingsQuery({
|
|
17345
17387
|
mentor: mentorId,
|
|
@@ -17347,7 +17389,7 @@ function useMentorSettings({ mentorId, tenantKey, username, }) {
|
|
|
17347
17389
|
// @ts-expect-error - userId is passed but not in generated API types
|
|
17348
17390
|
userId: username !== null && username !== void 0 ? username : "",
|
|
17349
17391
|
}, {
|
|
17350
|
-
skip: !username || !isLoggedIn,
|
|
17392
|
+
skip: !username || !isLoggedIn || !!isPublicRoute,
|
|
17351
17393
|
});
|
|
17352
17394
|
const { data: mentorPublicSettings } = useGetMentorPublicSettingsQuery({
|
|
17353
17395
|
mentor: mentorId,
|
|
@@ -17359,44 +17401,26 @@ function useMentorSettings({ mentorId, tenantKey, username, }) {
|
|
|
17359
17401
|
});
|
|
17360
17402
|
return {
|
|
17361
17403
|
data: {
|
|
17362
|
-
profileImage:
|
|
17363
|
-
|
|
17364
|
-
|
|
17365
|
-
|
|
17366
|
-
|
|
17367
|
-
|
|
17368
|
-
|
|
17369
|
-
|
|
17370
|
-
|
|
17371
|
-
|
|
17372
|
-
|
|
17373
|
-
|
|
17374
|
-
|
|
17375
|
-
|
|
17376
|
-
|
|
17377
|
-
: mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.mentor_unique_id,
|
|
17378
|
-
mentorVisibility: isLoggedIn
|
|
17379
|
-
? mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.mentor_visibility
|
|
17380
|
-
: mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.mentor_visibility,
|
|
17381
|
-
mentorName: (_a = mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.mentor) !== null && _a !== void 0 ? _a : mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.mentor,
|
|
17382
|
-
enableGuidedPrompts: isLoggedIn
|
|
17383
|
-
? mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.enable_guided_prompts
|
|
17384
|
-
: mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.enable_guided_prompts,
|
|
17385
|
-
mentorSlug: isLoggedIn
|
|
17386
|
-
? mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.mentor_slug
|
|
17387
|
-
: mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.mentor_slug,
|
|
17388
|
-
safetyDisclaimer: isLoggedIn
|
|
17389
|
-
? (_b = mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.metadata) === null || _b === void 0 ? void 0 : _b.safety_disclaimer
|
|
17390
|
-
: (_c = mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.metadata) === null || _c === void 0 ? void 0 : _c.safety_disclaimer,
|
|
17391
|
-
mentorTools: isLoggedIn
|
|
17392
|
-
? mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.mentor_tools
|
|
17393
|
-
: mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.mentor_tools,
|
|
17394
|
-
allowAnonymous: (_d = mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.allow_anonymous) !== null && _d !== void 0 ? _d : mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.allow_anonymous,
|
|
17404
|
+
profileImage: (_a = mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.profile_image) !== null && _a !== void 0 ? _a : mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.profile_image,
|
|
17405
|
+
greetingMethod: (_b = mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.greeting_method) !== null && _b !== void 0 ? _b : mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.greeting_method,
|
|
17406
|
+
proactiveResponse: (_c = mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.proactive_response) !== null && _c !== void 0 ? _c : mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.proactive_response,
|
|
17407
|
+
llmProvider: (mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.llm_provider) ||
|
|
17408
|
+
(mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.llm_provider) ||
|
|
17409
|
+
"",
|
|
17410
|
+
llmName: (_d = mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.llm_name) !== null && _d !== void 0 ? _d : mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.llm_name,
|
|
17411
|
+
mentorUniqueId: (_e = mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.mentor_unique_id) !== null && _e !== void 0 ? _e : mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.mentor_unique_id,
|
|
17412
|
+
mentorVisibility: (_f = mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.mentor_visibility) !== null && _f !== void 0 ? _f : mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.mentor_visibility,
|
|
17413
|
+
mentorName: (_g = mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.mentor) !== null && _g !== void 0 ? _g : mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.mentor,
|
|
17414
|
+
enableGuidedPrompts: (_h = mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.enable_guided_prompts) !== null && _h !== void 0 ? _h : mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.enable_guided_prompts,
|
|
17415
|
+
mentorSlug: (_j = mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.mentor_slug) !== null && _j !== void 0 ? _j : mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.mentor_slug,
|
|
17416
|
+
safetyDisclaimer: (_l = (_k = mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.metadata) === null || _k === void 0 ? void 0 : _k.safety_disclaimer) !== null && _l !== void 0 ? _l : (_m = mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.metadata) === null || _m === void 0 ? void 0 : _m.safety_disclaimer,
|
|
17417
|
+
mentorTools: (_o = mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.mentor_tools) !== null && _o !== void 0 ? _o : mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.mentor_tools,
|
|
17418
|
+
allowAnonymous: (_p = mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.allow_anonymous) !== null && _p !== void 0 ? _p : mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.allow_anonymous,
|
|
17395
17419
|
},
|
|
17396
17420
|
};
|
|
17397
17421
|
}
|
|
17398
17422
|
|
|
17399
|
-
function useAdvancedChat({ tenantKey, mentorId, username = ANONYMOUS_USERNAME, token, wsUrl, stopGenerationWsUrl, redirectToAuthSpa, errorHandler, sendMessageToParentWebsite, isPreviewMode, mentorShareableToken, on402Error, cachedSessionId, onStartNewChat, onOAuthRequired, onOAuthResolved, isOffline = false, onOfflineWithoutLocalLLM, }) {
|
|
17423
|
+
function useAdvancedChat({ tenantKey, mentorId, username = ANONYMOUS_USERNAME, token, wsUrl, stopGenerationWsUrl, redirectToAuthSpa, errorHandler, sendMessageToParentWebsite, isPreviewMode, mentorShareableToken, on402Error, cachedSessionId, onStartNewChat, onOAuthRequired, onOAuthResolved, isOffline = false, onOfflineWithoutLocalLLM, isPublicRoute, }) {
|
|
17400
17424
|
var _a, _b, _c, _d;
|
|
17401
17425
|
const dispatch = useDispatch();
|
|
17402
17426
|
const [createSessionId, { isLoading: isLoadingSessionIds }] = dataLayer.useCreateSessionIdMutation();
|
|
@@ -17416,6 +17440,7 @@ function useAdvancedChat({ tenantKey, mentorId, username = ANONYMOUS_USERNAME, t
|
|
|
17416
17440
|
mentorId,
|
|
17417
17441
|
tenantKey,
|
|
17418
17442
|
username,
|
|
17443
|
+
isPublicRoute,
|
|
17419
17444
|
});
|
|
17420
17445
|
const onStreamingChange = (streamingState) => {
|
|
17421
17446
|
dispatch(chatActions.setStreaming(streamingState));
|
|
@@ -17728,26 +17753,30 @@ function hasTool(tools, mentorSettings, toolSlug) {
|
|
|
17728
17753
|
// Check if the specific tool exists in both available tools and enabled tools
|
|
17729
17754
|
return tools.some((tool) => tool.slug === toolSlug && enabledToolSlugs.has(tool.slug));
|
|
17730
17755
|
}
|
|
17731
|
-
function useMentorTools({ tenantKey, mentorId, username = ANONYMOUS_USERNAME, errorHandler, }) {
|
|
17756
|
+
function useMentorTools({ tenantKey, mentorId, username = ANONYMOUS_USERNAME, errorHandler, isPublicRoute, }) {
|
|
17732
17757
|
var _a;
|
|
17733
17758
|
const dispatch = useDispatch();
|
|
17734
17759
|
const activeTools = useSelector(selectTools);
|
|
17735
17760
|
const artifactsEnabled = useSelector(selectArtifactsEnabled);
|
|
17736
17761
|
const sessionId = useSelector(selectSessionId);
|
|
17737
17762
|
const [editSession] = dataLayer.useEditSessionMutation();
|
|
17738
|
-
const { data:
|
|
17763
|
+
const { data: apiTools } = dataLayer.useGetToolsQuery({
|
|
17739
17764
|
mentor: mentorId,
|
|
17740
17765
|
org: tenantKey,
|
|
17741
17766
|
// @ts-expect-error - userId is passed but not in generated API types
|
|
17742
17767
|
userId: username !== null && username !== void 0 ? username : "",
|
|
17743
17768
|
}, {
|
|
17744
|
-
skip: !username || username === ANONYMOUS_USERNAME,
|
|
17769
|
+
skip: !username || username === ANONYMOUS_USERNAME || !!isPublicRoute,
|
|
17745
17770
|
});
|
|
17746
17771
|
const { data: mentorSettings } = useMentorSettings({
|
|
17747
17772
|
mentorId,
|
|
17748
17773
|
tenantKey,
|
|
17749
17774
|
username,
|
|
17775
|
+
isPublicRoute,
|
|
17750
17776
|
});
|
|
17777
|
+
// Fall back to mentor_tools from public settings when available-tools endpoint
|
|
17778
|
+
// is blocked by RBAC (403). This ensures shareable link users see tool buttons.
|
|
17779
|
+
const tools = apiTools !== null && apiTools !== void 0 ? apiTools : mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.mentorTools;
|
|
17751
17780
|
const { data: prompts } = dataLayer.useGetPromptsSearchQuery({
|
|
17752
17781
|
org: tenantKey,
|
|
17753
17782
|
username: username !== null && username !== void 0 ? username : "",
|
|
@@ -17757,7 +17786,7 @@ function useMentorTools({ tenantKey, mentorId, username = ANONYMOUS_USERNAME, er
|
|
|
17757
17786
|
mentor: mentorId,
|
|
17758
17787
|
orderDirection: "asc",
|
|
17759
17788
|
}, {
|
|
17760
|
-
skip: !tenantKey || !username || !mentorId,
|
|
17789
|
+
skip: !tenantKey || !username || !mentorId || !!isPublicRoute,
|
|
17761
17790
|
});
|
|
17762
17791
|
const updateSessionTools = async (tool) => {
|
|
17763
17792
|
let toolsToAdd = activeTools;
|