@iblai/web-utils 1.1.9 → 1.1.10

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
@@ -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 && isLoggedIn) {
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
  }
@@ -15548,6 +15559,24 @@ createApi({
15548
15559
  }),
15549
15560
  });
15550
15561
 
15562
+ createApi({
15563
+ reducerPath: 'analyticsCustomApiSlice',
15564
+ baseQuery: iblFetchBaseQuery,
15565
+ tagTypes: ['Analytics'],
15566
+ endpoints: (builder) => ({
15567
+ getDownloadReportFromURL: builder.query({
15568
+ query: ({ url }) => ({
15569
+ url: url,
15570
+ service: SERVICES.DM,
15571
+ method: 'GET',
15572
+ responseHandler: (response) => response.blob(),
15573
+ }),
15574
+ // Blobs are non-serializable; disable caching to prevent Redux serialization warnings
15575
+ keepUnusedDataFor: 0,
15576
+ }),
15577
+ }),
15578
+ });
15579
+
15551
15580
  createApi({
15552
15581
  reducerPath: 'reportsApiSlice',
15553
15582
  baseQuery: iblFakeBaseQuery,
@@ -17338,8 +17367,8 @@ createApi({
17338
17367
  }),
17339
17368
  });
17340
17369
 
17341
- function useMentorSettings({ mentorId, tenantKey, username, }) {
17342
- var _a, _b, _c, _d;
17370
+ function useMentorSettings({ mentorId, tenantKey, username, isPublicRoute, }) {
17371
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
17343
17372
  const isLoggedIn = username !== ANONYMOUS_USERNAME;
17344
17373
  const { data: mentorSettings } = useGetMentorSettingsQuery({
17345
17374
  mentor: mentorId,
@@ -17347,7 +17376,7 @@ function useMentorSettings({ mentorId, tenantKey, username, }) {
17347
17376
  // @ts-expect-error - userId is passed but not in generated API types
17348
17377
  userId: username !== null && username !== void 0 ? username : "",
17349
17378
  }, {
17350
- skip: !username || !isLoggedIn,
17379
+ skip: !username || !isLoggedIn || !!isPublicRoute,
17351
17380
  });
17352
17381
  const { data: mentorPublicSettings } = useGetMentorPublicSettingsQuery({
17353
17382
  mentor: mentorId,
@@ -17359,44 +17388,26 @@ function useMentorSettings({ mentorId, tenantKey, username, }) {
17359
17388
  });
17360
17389
  return {
17361
17390
  data: {
17362
- profileImage: isLoggedIn
17363
- ? mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.profile_image
17364
- : mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.profile_image,
17365
- greetingMethod: isLoggedIn
17366
- ? mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.greeting_method
17367
- : mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.greeting_method,
17368
- proactiveResponse: isLoggedIn
17369
- ? mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.proactive_response
17370
- : mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.proactive_response,
17371
- llmProvider: isLoggedIn ? mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.llm_provider : "",
17372
- llmName: isLoggedIn
17373
- ? mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.llm_name
17374
- : mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.llm_name,
17375
- mentorUniqueId: isLoggedIn
17376
- ? mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.mentor_unique_id
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,
17391
+ 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,
17392
+ 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,
17393
+ 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,
17394
+ llmProvider: (mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.llm_provider) ||
17395
+ (mentorPublicSettings === null || mentorPublicSettings === void 0 ? void 0 : mentorPublicSettings.llm_provider) ||
17396
+ "",
17397
+ 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,
17398
+ 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,
17399
+ 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,
17400
+ 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,
17401
+ 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,
17402
+ 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,
17403
+ 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,
17404
+ 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,
17405
+ 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
17406
  },
17396
17407
  };
17397
17408
  }
17398
17409
 
17399
- function useAdvancedChat({ tenantKey, mentorId, username = ANONYMOUS_USERNAME, token, wsUrl, stopGenerationWsUrl, redirectToAuthSpa, errorHandler, sendMessageToParentWebsite, isPreviewMode, mentorShareableToken, on402Error, cachedSessionId, onStartNewChat, onOAuthRequired, onOAuthResolved, isOffline = false, onOfflineWithoutLocalLLM, }) {
17410
+ 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
17411
  var _a, _b, _c, _d;
17401
17412
  const dispatch = useDispatch();
17402
17413
  const [createSessionId, { isLoading: isLoadingSessionIds }] = dataLayer.useCreateSessionIdMutation();
@@ -17416,6 +17427,7 @@ function useAdvancedChat({ tenantKey, mentorId, username = ANONYMOUS_USERNAME, t
17416
17427
  mentorId,
17417
17428
  tenantKey,
17418
17429
  username,
17430
+ isPublicRoute,
17419
17431
  });
17420
17432
  const onStreamingChange = (streamingState) => {
17421
17433
  dispatch(chatActions.setStreaming(streamingState));
@@ -17728,26 +17740,30 @@ function hasTool(tools, mentorSettings, toolSlug) {
17728
17740
  // Check if the specific tool exists in both available tools and enabled tools
17729
17741
  return tools.some((tool) => tool.slug === toolSlug && enabledToolSlugs.has(tool.slug));
17730
17742
  }
17731
- function useMentorTools({ tenantKey, mentorId, username = ANONYMOUS_USERNAME, errorHandler, }) {
17743
+ function useMentorTools({ tenantKey, mentorId, username = ANONYMOUS_USERNAME, errorHandler, isPublicRoute, }) {
17732
17744
  var _a;
17733
17745
  const dispatch = useDispatch();
17734
17746
  const activeTools = useSelector(selectTools);
17735
17747
  const artifactsEnabled = useSelector(selectArtifactsEnabled);
17736
17748
  const sessionId = useSelector(selectSessionId);
17737
17749
  const [editSession] = dataLayer.useEditSessionMutation();
17738
- const { data: tools } = dataLayer.useGetToolsQuery({
17750
+ const { data: apiTools } = dataLayer.useGetToolsQuery({
17739
17751
  mentor: mentorId,
17740
17752
  org: tenantKey,
17741
17753
  // @ts-expect-error - userId is passed but not in generated API types
17742
17754
  userId: username !== null && username !== void 0 ? username : "",
17743
17755
  }, {
17744
- skip: !username || username === ANONYMOUS_USERNAME,
17756
+ skip: !username || username === ANONYMOUS_USERNAME || !!isPublicRoute,
17745
17757
  });
17746
17758
  const { data: mentorSettings } = useMentorSettings({
17747
17759
  mentorId,
17748
17760
  tenantKey,
17749
17761
  username,
17762
+ isPublicRoute,
17750
17763
  });
17764
+ // Fall back to mentor_tools from public settings when available-tools endpoint
17765
+ // is blocked by RBAC (403). This ensures shareable link users see tool buttons.
17766
+ const tools = apiTools !== null && apiTools !== void 0 ? apiTools : mentorSettings === null || mentorSettings === void 0 ? void 0 : mentorSettings.mentorTools;
17751
17767
  const { data: prompts } = dataLayer.useGetPromptsSearchQuery({
17752
17768
  org: tenantKey,
17753
17769
  username: username !== null && username !== void 0 ? username : "",
@@ -17757,7 +17773,7 @@ function useMentorTools({ tenantKey, mentorId, username = ANONYMOUS_USERNAME, er
17757
17773
  mentor: mentorId,
17758
17774
  orderDirection: "asc",
17759
17775
  }, {
17760
- skip: !tenantKey || !username || !mentorId,
17776
+ skip: !tenantKey || !username || !mentorId || !!isPublicRoute,
17761
17777
  });
17762
17778
  const updateSessionTools = async (tool) => {
17763
17779
  let toolsToAdd = activeTools;