@iblai/web-utils 1.10.12 → 1.11.2

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.
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Chat-privacy modes mirror the backend `ChatPrivacyModeEnum`. Kept as
3
+ * string-literal constants here so the data-layer doesn't depend on the
4
+ * generated `@iblai/iblai-api` types for this feature — swap to the
5
+ * generated enum once the client is regenerated.
6
+ */
7
+ export type ChatPrivacyMode = 'normal' | 'anonymized' | 'disabled';
8
+ export declare const ChatPrivacyModeEnum: {
9
+ readonly NORMAL: "normal";
10
+ readonly ANONYMIZED: "anonymized";
11
+ readonly DISABLED: "disabled";
12
+ };
13
+ export declare const CHAT_PRIVACY_MODES: ChatPrivacyMode[];
@@ -21,6 +21,8 @@ export * from './features/core/constants';
21
21
  export * from './features/skills/api-slice';
22
22
  export * from './features/credentials/api-slice';
23
23
  export * from './features/credentials/types';
24
+ export * from './features/chat-privacy/api-slice';
25
+ export * from './features/chat-privacy/constants';
24
26
  export * from './features/user-invitations/api-slice';
25
27
  export * from './features/apps/api-slice';
26
28
  export * from './features/billing/api-slice';
package/dist/index.d.ts CHANGED
@@ -17,6 +17,20 @@ import { Slice as Slice$1, Reducer as Reducer$1 } from '@reduxjs/toolkit/react';
17
17
  import * as redux from 'redux';
18
18
  import * as mitt from 'mitt';
19
19
 
20
+ interface UseTenantSwitchSyncOptions {
21
+ /** Called when ANOTHER tab broadcasts a tenant switch (self-echo filtered out). */
22
+ onRemoteSwitch?: (tenant: string) => void;
23
+ }
24
+ /**
25
+ * Subscribe to cross-tab tenant-switch broadcasts. Ignores this tab's own echo
26
+ * (BroadcastChannel delivers to sibling instances in the same tab) and refreshes
27
+ * the shared switch lock so this tab won't auto-revert during the switch window.
28
+ *
29
+ * @example
30
+ * useTenantSwitchSync();
31
+ */
32
+ declare function useTenantSwitchSync(options?: UseTenantSwitchSyncOptions): void;
33
+
20
34
  interface Tenant$2 {
21
35
  key: string;
22
36
  is_admin: boolean;
@@ -1018,6 +1032,68 @@ interface HandleLogoutOptions {
1018
1032
  * ```
1019
1033
  */
1020
1034
  declare function handleLogout(options: HandleLogoutOptions): void;
1035
+ declare const TENANT_SWITCH_CHANNEL = "ibl-tenant-switch";
1036
+ declare const TENANT_SWITCH_LOCK_KEY = "ibl_tenant_switch_lock";
1037
+ declare const DEFAULT_TENANT_SWITCH_LOCK_TTL_MS = 8000;
1038
+ interface TenantSwitchLock {
1039
+ tenant: string;
1040
+ /** `${ts}-${tabId}` — monotonic; newer wins. */
1041
+ token: string;
1042
+ ts: number;
1043
+ senderId: string;
1044
+ }
1045
+ /**
1046
+ * Stable per-tab id. Uses sessionStorage so it survives same-tab reloads while
1047
+ * staying unique per tab/window.
1048
+ */
1049
+ declare function getTabId(): string;
1050
+ /** The active (non-expired) tenant-switch lock, or null. */
1051
+ declare function readTenantSwitchLock(ttlMs?: number): TenantSwitchLock | null;
1052
+ /** Write a fresh lock for `tenant` (newest intent). Returns the lock written. */
1053
+ declare function writeTenantSwitchLock(tenant: string): TenantSwitchLock;
1054
+ /** Extend an existing lock's window from "now" (no-op when no active lock). */
1055
+ declare function refreshTenantSwitchLock(): void;
1056
+ declare function clearTenantSwitchLock(): void;
1057
+ /** True while a tenant switch is in flight — gate automatic reverts on this. */
1058
+ declare function isTenantSwitchInProgress(ttlMs?: number): boolean;
1059
+ interface HandleTenantSwitchOptions {
1060
+ /** Auth SPA base URL (e.g. config.authUrl()). */
1061
+ authUrl: string;
1062
+ /** localStorage key for the saved redirect path (default "redirect-to"). */
1063
+ redirectPathStorageKey?: string;
1064
+ /** localStorage key for a JWT to forward through the switch (default "edx_jwt_token"). */
1065
+ preserveTokenKey?: string;
1066
+ /** localStorage key holding the tenant (default "tenant"). */
1067
+ tenantStorageKey?: string;
1068
+ /** Cookie name signalling a switch is in progress (default "ibl_tenant_switching"). */
1069
+ tenantSwitchingCookie?: string;
1070
+ /** Query-param names for the auth URL. */
1071
+ queryParams?: {
1072
+ tenant?: string;
1073
+ redirectTo?: string;
1074
+ };
1075
+ /** Persist the current path so the app returns to it post-switch. */
1076
+ saveRedirect?: boolean;
1077
+ /** Explicit redirect target (defaults to window.location.origin). */
1078
+ redirectUrl?: string;
1079
+ /** Broadcast to other tabs + clear storage (true for user-initiated; default true). */
1080
+ broadcast?: boolean;
1081
+ /** Lock TTL override. */
1082
+ lockTtlMs?: number;
1083
+ /** Injected so this util stays React-free (mentorai passes the SDK's). */
1084
+ clearCurrentTenantCookie?: () => void;
1085
+ }
1086
+ /**
1087
+ * Switch the active tenant. Coordinates across tabs (TTL lock + BroadcastChannel),
1088
+ * clears storage, then redirects through the auth SPA's `/login/complete`.
1089
+ *
1090
+ * @example
1091
+ * await handleTenantSwitch("acme", {
1092
+ * authUrl: config.authUrl(),
1093
+ * clearCurrentTenantCookie,
1094
+ * });
1095
+ */
1096
+ declare function handleTenantSwitch(tenant: string, options: HandleTenantSwitchOptions): Promise<void>;
1021
1097
 
1022
1098
  declare const isReactNative: () => boolean;
1023
1099
  declare const isWeb: () => boolean;
@@ -1025,7 +1101,7 @@ declare const isNode: () => string | false;
1025
1101
  declare const isExpo: () => any;
1026
1102
  declare const isTauri: () => boolean;
1027
1103
  declare function isSafariBrowser(): boolean;
1028
- declare const getPlatform: () => "web" | "react-native" | "node" | "unknown";
1104
+ declare const getPlatform: () => "react-native" | "web" | "node" | "unknown";
1029
1105
  declare const safeRequire: (moduleName: string) => any;
1030
1106
  declare const getNextNavigation: () => any;
1031
1107
 
@@ -2380,5 +2456,5 @@ declare const WithPermissions: ({ rbacResource, rbacPermissions, children, }: Wi
2380
2456
  */
2381
2457
  declare const checkRbacPermission: (rbacPermissions: object, rbacResource: string, enableRBAC?: boolean) => boolean;
2382
2458
 
2383
- export { ALPHANUMERIC_32_REGEX, ANONYMOUS_USERNAME, AuthContext, AuthContextProvider, AuthProvider, CHAT_AREA_SIZE, CacheKeys, DEFAULT_DISCLAIMER_CONTENT, LOCAL_STORAGE_KEYS, MAX_INITIAL_WEBSOCKET_CONNECTION_ATTEMPTS, MENTOR_CHAT_DOCUMENTS_EXTENSIONS, MENTOR_VISIBILITY, MENTOR_VISIBILITY_VALUES, METADATAS, MentorProvider, REQUIRED_ACTIONS_FOR_GROUPS, RemoteEvents, STREAMING_CONTENT_BUFFER_THRESHOLD, STREAMING_CONTENT_FLUSH_INTERVAL, SUBSCRIPTION_MESSAGES, SUBSCRIPTION_PACKAGES, SUBSCRIPTION_PACKAGES_V2, SUBSCRIPTION_TRIGGERS, SUBSCRIPTION_V2_TRIGGERS, ServiceWorkerProvider, SubscriptionFlow, SubscriptionFlowV2, TOOLS, TOOL_NAME_MAP, TenantContext, TenantContextProvider, TenantProvider, TimeTracker, WithFormPermissions, WithPermissions, addFiles, addMessage, addProtocolToUrl, advancedTabs, advancedTabsProperties, appleRestrictionReducer, appleRestrictionSlice, chatActions, chatInputSlice, chatInputSliceActions, chatInputSliceReducer, chatInputSliceSelectors, chatSliceReducerShared, checkModelAvailable, checkOllamaHealth, checkRbacPermission, clearAllCaches, clearApiCache, clearAuthCookies, clearCookies, clearCurrentTenantCookie, clearFiles, clearMessages, combineCSVData, convertToOllamaMessages, createFileReference, createMultipleFileReferences, csvDataToText, defaultSessionIds, deleteCookie, deleteCookieOnAllDomains, enableChatActionsPopup, eventBus, fetchWithCache, filesReducer, filesSlice, formatRelativeTime, getAuthSpaJoinUrl, getCacheStatus, getCachedApiResponse, getCookieValue, getDomainParts, getFileInfo, getInitials, getLocalLLMSystemPrompt, getNextNavigation, getParentDomain, getPlatform, getPlatformKey, getServiceWorkerStatus, getStoredUserName, getTimeAgo, getUserEmail, getUserName, handleLogout, hasNonExpiredAuthToken, hostChatReducer, hostChatSlice, initServiceWorker, isAlphaNumeric32, isExpo, isFileAccepted, isInIframe, isJSON, isLoggedIn, isNode, isReactNative, isSafariBrowser, isServiceWorkerSupported, isStripeActivated, isTauri, isTauriOfflineMode, isWeb, loadMetadataConfig, markdownToPlainText, monetizationSlice, onStatusChange, onUpdate, parseCSV, preCacheMentorData, rbacReducer, redirectToAuthSpa, redirectToAuthSpaJoinTenant, registerServiceWorker, removeFile, requestPresignedUrl, safeRequire, selectActiveChatMessages, selectActiveTab, selectArtifactsEnabled, selectAttachedFiles, selectChats, selectCurrentStreamingArtifact, selectCurrentStreamingMessage, selectDocumentFilter, selectEnableChatActionsPopup, selectIframeContext, selectIsError, selectIsPending, selectIsReasoning, selectIsStopped, selectIsTyping, selectLastArtifactContentFlushTime, selectMetadata, selectNumberOfActiveChatMessages, selectRbacPermissions, selectSessionId, selectSessionIds, selectShouldStartNewChat, selectShowingSharedChat, selectStatus, selectStreaming, selectStreamingArtifactContentBuffer, selectStreamingArtifactFullContent, selectStreamingReasoningContent, selectStreamingToolCalls, selectToken, selectTokenEnabled, selectTools, sendMessageToParentWebsite, setAccessCheckResponse, setAdvancedDisplayMonetizationCheckoutModal, setCachedApiResponse, setCookieForAuth, setDisplayMonetizationCheckoutModal, setError402Detected, setFreeTrialUsageOptions, setOfflineStatus, setOpenAppleRestrictionModal, setOpenPricingModal, setPricingModalData, setSubscriptionStatus, setTauriMode, setTopBannerOptions, setupNetworkListeners, showMonetizationCheckoutModal, skipWaiting, streamOllamaChat, subscriptionReducer, subscriptionSlice, syncAuthToCookies, tenantKeySchema, tenantSchema, topBannerReducer, topBannerSlice, translatePrompt, unregisterServiceWorker, updateFileMetadata, updateFileProgress, updateFileRetryCount, updateFileStatus, updateFileUrl, updateFileUrlFromWebSocket, updateRbacPermissions, uploadToS3, use402ErrorCheck, useAccessingPublicRoute, useAdvancedChat, useAuthContext, useAuthProvider, useAxdToken, useCachedSessionId, useChat, useChatFileUpload, useCurrentTenant, useDayJs, useDmToken, useEmbedMode, useEventCallback, useEventListener, useExternalPricingPlan, useFileDragDrop, useIsAdmin, useIsomorphicLayoutEffect, useLocalStorage, useMentorSettings, useMentorTools, useModelFileUploadCapabilities, useOS, useProfileImageUpload, useResponsive, useServiceWorker, useShowAttachment, useShowFreeTrialDialog, useShowVoiceCall, useShowVoiceRecorder, useStripeUpgrade, useSubscriptionHandler, useSubscriptionHandlerV2, useTenantContext, useTenantMetadata, useTimeTracker, useTimeTrackerNative, useTimer, useUserAgreement, useUserData, useUserProfileUpdate, useUserTenants, useUsername, useVisitingTenant, useVoiceChat, useWelcome as useWelcomeMessage, userDataSchema, validateFile };
2384
- export type { AdvancedTab, AppleRestrictionState, ArtifactData, ArtifactPayload, ArtifactVersion, AttachedFile, AuthContextType, ChatInputState, ChatMode, ChatSliceState, ChatState, ChatStatus, CreateStripeCustomerPortalRequest, Error402MessageData, FileAttachment, FileInfo, FileProcessingEvent, FileReference, FileUploadCapabilities, FileUploadState, FilesState, HandleLogoutOptions, HostChatState, Message$1 as Message, MessageAction, MonetizationState, OAuthRequiredData, OAuthResolvedData, OllamaChatRequest, OllamaChatStreamResponse, OllamaMessage, OllamaStreamCallbacks, PricingModalData$1 as PricingModalData, PricingTablePayload, Prompt, RawMessageFromWS, RbacPermissions, RbacState, RedirectToAuthSpaOptions, SendMessageOptions, ServiceWorkerStatus, SessionIds, StreamingArtifact, StreamingMessage, StripeUpgradePlan, SubscriptionFlowConfig, SubscriptionFlowConfigV2, SubscriptionState, Tenant, TenantContextType, TenantKeyMentorIdParams, TenantMetadata, TimeTrackerConfig, TimeTrackerState, ToolCallInfo, TopBannerOptions, TopBannerState, TopTrialBannerProps, UploadProgressCallback, UseChatProps, UseChatReturn, UseExternalPricingProps, UseProfileImageUploadOptions, UseProfileImageUploadReturn, UseTimeTrackerConfig, UseTimeTrackerNativeConfig, UseTimeTrackerNativeReturn, UseTimeTrackerReturn, UseUserProfileUpdateResult, UserProfileUpdateData };
2459
+ export { ALPHANUMERIC_32_REGEX, ANONYMOUS_USERNAME, AuthContext, AuthContextProvider, AuthProvider, CHAT_AREA_SIZE, CacheKeys, DEFAULT_DISCLAIMER_CONTENT, DEFAULT_TENANT_SWITCH_LOCK_TTL_MS, LOCAL_STORAGE_KEYS, MAX_INITIAL_WEBSOCKET_CONNECTION_ATTEMPTS, MENTOR_CHAT_DOCUMENTS_EXTENSIONS, MENTOR_VISIBILITY, MENTOR_VISIBILITY_VALUES, METADATAS, MentorProvider, REQUIRED_ACTIONS_FOR_GROUPS, RemoteEvents, STREAMING_CONTENT_BUFFER_THRESHOLD, STREAMING_CONTENT_FLUSH_INTERVAL, SUBSCRIPTION_MESSAGES, SUBSCRIPTION_PACKAGES, SUBSCRIPTION_PACKAGES_V2, SUBSCRIPTION_TRIGGERS, SUBSCRIPTION_V2_TRIGGERS, ServiceWorkerProvider, SubscriptionFlow, SubscriptionFlowV2, TENANT_SWITCH_CHANNEL, TENANT_SWITCH_LOCK_KEY, TOOLS, TOOL_NAME_MAP, TenantContext, TenantContextProvider, TenantProvider, TimeTracker, WithFormPermissions, WithPermissions, addFiles, addMessage, addProtocolToUrl, advancedTabs, advancedTabsProperties, appleRestrictionReducer, appleRestrictionSlice, chatActions, chatInputSlice, chatInputSliceActions, chatInputSliceReducer, chatInputSliceSelectors, chatSliceReducerShared, checkModelAvailable, checkOllamaHealth, checkRbacPermission, clearAllCaches, clearApiCache, clearAuthCookies, clearCookies, clearCurrentTenantCookie, clearFiles, clearMessages, clearTenantSwitchLock, combineCSVData, convertToOllamaMessages, createFileReference, createMultipleFileReferences, csvDataToText, defaultSessionIds, deleteCookie, deleteCookieOnAllDomains, enableChatActionsPopup, eventBus, fetchWithCache, filesReducer, filesSlice, formatRelativeTime, getAuthSpaJoinUrl, getCacheStatus, getCachedApiResponse, getCookieValue, getDomainParts, getFileInfo, getInitials, getLocalLLMSystemPrompt, getNextNavigation, getParentDomain, getPlatform, getPlatformKey, getServiceWorkerStatus, getStoredUserName, getTabId, getTimeAgo, getUserEmail, getUserName, handleLogout, handleTenantSwitch, hasNonExpiredAuthToken, hostChatReducer, hostChatSlice, initServiceWorker, isAlphaNumeric32, isExpo, isFileAccepted, isInIframe, isJSON, isLoggedIn, isNode, isReactNative, isSafariBrowser, isServiceWorkerSupported, isStripeActivated, isTauri, isTauriOfflineMode, isTenantSwitchInProgress, isWeb, loadMetadataConfig, markdownToPlainText, monetizationSlice, onStatusChange, onUpdate, parseCSV, preCacheMentorData, rbacReducer, readTenantSwitchLock, redirectToAuthSpa, redirectToAuthSpaJoinTenant, refreshTenantSwitchLock, registerServiceWorker, removeFile, requestPresignedUrl, safeRequire, selectActiveChatMessages, selectActiveTab, selectArtifactsEnabled, selectAttachedFiles, selectChats, selectCurrentStreamingArtifact, selectCurrentStreamingMessage, selectDocumentFilter, selectEnableChatActionsPopup, selectIframeContext, selectIsError, selectIsPending, selectIsReasoning, selectIsStopped, selectIsTyping, selectLastArtifactContentFlushTime, selectMetadata, selectNumberOfActiveChatMessages, selectRbacPermissions, selectSessionId, selectSessionIds, selectShouldStartNewChat, selectShowingSharedChat, selectStatus, selectStreaming, selectStreamingArtifactContentBuffer, selectStreamingArtifactFullContent, selectStreamingReasoningContent, selectStreamingToolCalls, selectToken, selectTokenEnabled, selectTools, sendMessageToParentWebsite, setAccessCheckResponse, setAdvancedDisplayMonetizationCheckoutModal, setCachedApiResponse, setCookieForAuth, setDisplayMonetizationCheckoutModal, setError402Detected, setFreeTrialUsageOptions, setOfflineStatus, setOpenAppleRestrictionModal, setOpenPricingModal, setPricingModalData, setSubscriptionStatus, setTauriMode, setTopBannerOptions, setupNetworkListeners, showMonetizationCheckoutModal, skipWaiting, streamOllamaChat, subscriptionReducer, subscriptionSlice, syncAuthToCookies, tenantKeySchema, tenantSchema, topBannerReducer, topBannerSlice, translatePrompt, unregisterServiceWorker, updateFileMetadata, updateFileProgress, updateFileRetryCount, updateFileStatus, updateFileUrl, updateFileUrlFromWebSocket, updateRbacPermissions, uploadToS3, use402ErrorCheck, useAccessingPublicRoute, useAdvancedChat, useAuthContext, useAuthProvider, useAxdToken, useCachedSessionId, useChat, useChatFileUpload, useCurrentTenant, useDayJs, useDmToken, useEmbedMode, useEventCallback, useEventListener, useExternalPricingPlan, useFileDragDrop, useIsAdmin, useIsomorphicLayoutEffect, useLocalStorage, useMentorSettings, useMentorTools, useModelFileUploadCapabilities, useOS, useProfileImageUpload, useResponsive, useServiceWorker, useShowAttachment, useShowFreeTrialDialog, useShowVoiceCall, useShowVoiceRecorder, useStripeUpgrade, useSubscriptionHandler, useSubscriptionHandlerV2, useTenantContext, useTenantMetadata, useTenantSwitchSync, useTimeTracker, useTimeTrackerNative, useTimer, useUserAgreement, useUserData, useUserProfileUpdate, useUserTenants, useUsername, useVisitingTenant, useVoiceChat, useWelcome as useWelcomeMessage, userDataSchema, validateFile, writeTenantSwitchLock };
2460
+ export type { AdvancedTab, AppleRestrictionState, ArtifactData, ArtifactPayload, ArtifactVersion, AttachedFile, AuthContextType, ChatInputState, ChatMode, ChatSliceState, ChatState, ChatStatus, CreateStripeCustomerPortalRequest, Error402MessageData, FileAttachment, FileInfo, FileProcessingEvent, FileReference, FileUploadCapabilities, FileUploadState, FilesState, HandleLogoutOptions, HandleTenantSwitchOptions, HostChatState, Message$1 as Message, MessageAction, MonetizationState, OAuthRequiredData, OAuthResolvedData, OllamaChatRequest, OllamaChatStreamResponse, OllamaMessage, OllamaStreamCallbacks, PricingModalData$1 as PricingModalData, PricingTablePayload, Prompt, RawMessageFromWS, RbacPermissions, RbacState, RedirectToAuthSpaOptions, SendMessageOptions, ServiceWorkerStatus, SessionIds, StreamingArtifact, StreamingMessage, StripeUpgradePlan, SubscriptionFlowConfig, SubscriptionFlowConfigV2, SubscriptionState, Tenant, TenantContextType, TenantKeyMentorIdParams, TenantMetadata, TenantSwitchLock, TimeTrackerConfig, TimeTrackerState, ToolCallInfo, TopBannerOptions, TopBannerState, TopTrialBannerProps, UploadProgressCallback, UseChatProps, UseChatReturn, UseExternalPricingProps, UseProfileImageUploadOptions, UseProfileImageUploadReturn, UseTenantSwitchSyncOptions, UseTimeTrackerConfig, UseTimeTrackerNativeConfig, UseTimeTrackerNativeReturn, UseTimeTrackerReturn, UseUserProfileUpdateResult, UserProfileUpdateData };