@iblai/web-utils 1.12.0 → 1.13.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/index.js CHANGED
@@ -27,6 +27,103 @@ function _interopNamespaceDefault(e) {
27
27
 
28
28
  var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
29
29
 
30
+ const MENTOR_CHAT_DOCUMENTS_EXTENSIONS = [
31
+ // Media types
32
+ "video/*",
33
+ "audio/*",
34
+ "image/*",
35
+ // Document types
36
+ ".docx",
37
+ ".xlsx",
38
+ ".pptx",
39
+ ".csv",
40
+ ".md",
41
+ ".txt",
42
+ ".pdf",
43
+ ];
44
+ const ANONYMOUS_USERNAME = "anonymous";
45
+ const DEFAULT_DISCLAIMER_CONTENT = `By accessing and using the [ibl.ai](http://ibl.ai/) MentorAI platform (“Platform”), you agree to the following terms. The Platform provides AI-powered mentorship and educational support. You understand that AI responses may contain inaccuracies, and you are responsible for independently verifying any information before relying on it for academic, professional, or personal decisions. Do not input confidential, sensitive, or personally identifiable information of yourself or others.
46
+ All content, code, and data processed through the Platform remain the property of their respective owners. [ibl.ai](http://ibl.ai/) retains all rights to the Platform’s underlying technology and intellectual property. You are granted a limited, non-exclusive, revocable license to use the Platform for personal or institutional learning purposes only.
47
+ Your use must comply with applicable laws and institutional policies. Misuse—including attempting to bypass security, copy source code, or use the service for unlawful activity—may result in suspension or termination of access. Continued use constitutes acceptance of these terms.`;
48
+ const MAX_INITIAL_WEBSOCKET_CONNECTION_ATTEMPTS = 3;
49
+ const LOCAL_STORAGE_KEYS = {
50
+ CURRENT_TENANT: "current_tenant",
51
+ TENANTS: "tenants",
52
+ REDIRECT_TO: "redirect-to",
53
+ AUTH_TOKEN: "axd_token",
54
+ TOKEN_EXPIRY: "axd_token_expires",
55
+ USER_DATA: "userData",
56
+ USER_TENANTS: "tenants",
57
+ VISITING_TENANT: "visiting_tenant",
58
+ SESSION_ID: "session_id",
59
+ EDX_TOKEN_KEY: "edx_jwt_token",
60
+ DM_TOKEN_KEY: "dm_token",
61
+ DM_TOKEN_EXPIRES: "dm_token_expires",
62
+ DM_TOKEN_EXPIRY: "dm_token_expires",
63
+ AXD_TOKEN_KEY: "axd_token",
64
+ DEFAULT_TENANT: "tenant",
65
+ MODEL_DOWNLOAD_STATE: "model_download_state",
66
+ MODEL_DOWNLOAD_PROMPT_DISMISSED: "model_download_prompt_dismissed",
67
+ };
68
+ const TOOLS = {
69
+ WEB_SEARCH: "web-search",
70
+ WIKIPEDIA_SEARCH: "wikipedia-search",
71
+ COURSE_CREATION: "course-creation",
72
+ MCP: "mcp",
73
+ IMAGE_GENERATION: "image-generation",
74
+ IBL_PATHWAY_DOCUMENTS_RETRIEVER: "ibl-pathway-documents-retriever",
75
+ TRAINED_DOCUMENTS: "trained-documents",
76
+ IBL_SESSION_DOCUMENTS_RETRIEVER: "ibl-session-documents-retriever",
77
+ PLAYWRIGHT_BROWSER: "playwright-browser",
78
+ HUMAN_SUPPORT: "human-support",
79
+ CODE_INTERPRETER: "code-interpreter",
80
+ DEEP_RESEARCH: "deep-research",
81
+ STUDY_MODE: "study-mode",
82
+ MEMORY: "memory",
83
+ SCREEN_SHARE: "screen-share",
84
+ POWERPOINT: "powerpoint",
85
+ PROMPT: "prompt",
86
+ QUIZ: "quiz",
87
+ RUBRIC: "rubric",
88
+ RESOURCE: "resource",
89
+ LESSON_PLAN: "lesson-plan",
90
+ SYLLABUS: "syllabus",
91
+ CANVAS: "canvas",
92
+ GOOGLE_SLIDES: "google-slides",
93
+ GOOGLE_DOCUMENT: "google-docs",
94
+ };
95
+ // Maps WebSocket tool_call type names to human-readable UI labels
96
+ const TOOL_NAME_MAP = {
97
+ web_search_call: "Searching the web",
98
+ vector_search: "Searching knowledge base",
99
+ calculator: "Calculating",
100
+ file_reader: "Reading file",
101
+ code_executor: "Running code",
102
+ wikipedia: "Searching Wikipedia",
103
+ };
104
+ const REQUIRED_ACTIONS_FOR_GROUPS = {
105
+ NOTIFICATIONS: "Ibl.Notifications/Notification/action",
106
+ };
107
+ const MENTOR_VISIBILITY_VALUES = {
108
+ ADMINISTRATORS: "viewable_by_tenant_admins",
109
+ STUDENTS: "viewable_by_tenant_students",
110
+ ANYONE: "viewable_by_anyone",
111
+ };
112
+ const MENTOR_VISIBILITY = [
113
+ {
114
+ label: "Administrators",
115
+ value: MENTOR_VISIBILITY_VALUES.ADMINISTRATORS,
116
+ },
117
+ {
118
+ label: "Users",
119
+ value: MENTOR_VISIBILITY_VALUES.STUDENTS,
120
+ },
121
+ {
122
+ label: "Anyone",
123
+ value: MENTOR_VISIBILITY_VALUES.ANYONE,
124
+ },
125
+ ];
126
+
30
127
  /**
31
128
  * Authentication and Authorization Utilities
32
129
  *
@@ -63,6 +160,61 @@ function deleteCookie(name, path, domain) {
63
160
  const domainValue = domain ? `domain=${domain};` : "";
64
161
  document.cookie = cookieValue + expires + pathValue + domainValue;
65
162
  }
163
+ /* Reads a JWT's `exp` claim and reports whether it is in the past. A token that
164
+ * cannot be decoded (or is malformed) is treated as expired; a token with no
165
+ * `exp` claim is treated as non-expiring (mirrors the axd "no expiry" case).
166
+ */
167
+ function isJwtExpired(token) {
168
+ try {
169
+ const payload = token.split(".")[1];
170
+ if (!payload)
171
+ return true;
172
+ const normalized = payload.replace(/-/g, "+").replace(/_/g, "/");
173
+ const padded = normalized.padEnd(normalized.length + ((4 - (normalized.length % 4)) % 4), "=");
174
+ const claims = JSON.parse(atob(padded));
175
+ if (typeof claims.exp !== "number")
176
+ return false;
177
+ return claims.exp * 1000 <= Date.now();
178
+ }
179
+ catch (_a) {
180
+ return true;
181
+ }
182
+ }
183
+ function hasNonExpiredAuthToken() {
184
+ // The edx JWT is stored alongside the axd token at SSO login; a valid session
185
+ // requires it to be present and unexpired too, so re-auth is triggered when
186
+ // it is missing or its `exp` has passed.
187
+ const edxToken = window.localStorage.getItem(LOCAL_STORAGE_KEYS.EDX_TOKEN_KEY);
188
+ if (!edxToken) {
189
+ console.log("################### [hasNonExpiredAuthToken] edx_jwt_token is not defined", edxToken);
190
+ return false;
191
+ }
192
+ if (isJwtExpired(edxToken)) {
193
+ console.log("################### [hasNonExpiredAuthToken] edx_jwt_token is expired");
194
+ return false;
195
+ }
196
+ const token = window.localStorage.getItem(LOCAL_STORAGE_KEYS.AUTH_TOKEN);
197
+ if (!token) {
198
+ console.log("################### [hasNonExpiredAuthToken] axd token is not defined", token);
199
+ return false;
200
+ }
201
+ const tokenExpiry = window.localStorage.getItem(LOCAL_STORAGE_KEYS.TOKEN_EXPIRY);
202
+ if (!tokenExpiry) {
203
+ console.log("################### [hasNonExpiredAuthToken] axd token expiry is not defined", tokenExpiry);
204
+ return true;
205
+ }
206
+ const expiryDate = new Date(tokenExpiry);
207
+ if (isNaN(expiryDate.getTime())) {
208
+ console.log("################### [hasNonExpiredAuthToken] axd token expiry date", expiryDate);
209
+ return false;
210
+ }
211
+ const currentDate = new Date();
212
+ if (expiryDate <= currentDate) {
213
+ console.log("################### [hasNonExpiredAuthToken] axd token expiry date is less than current date ", expiryDate, currentDate);
214
+ return false;
215
+ }
216
+ return true;
217
+ }
66
218
  /**
67
219
  * Get all possible domain parts for cookie deletion
68
220
  * @param domain - The domain to split
@@ -210,7 +362,7 @@ async function redirectToAuthSpa(options) {
210
362
  logoutTimestamp: "ibl_logout_timestamp",
211
363
  loginTimestamp: "ibl_login_timestamp",
212
364
  tenantSwitching: "ibl_tenant_switching",
213
- }, hasNonExpiredAuthToken, isOffline, preserveTokenKey, authRedirectProxy, isNativeApp, scheme = "iblai-mentor", forceRedirect = false, } = options;
365
+ }, isOffline, preserveTokenKey, authRedirectProxy, isNativeApp, scheme = "iblai-mentor", forceRedirect = false, } = options;
214
366
  console.log("[redirectToAuthSpa] starting redirect to auth spa", redirectTo, platformKey, logout, saveRedirect, forceRedirect);
215
367
  // Skip if a tenant switch is already in progress
216
368
  if (!forceRedirect &&
@@ -1042,6 +1194,13 @@ const SKILLS_AI_CONFIG = {
1042
1194
  description: "Allow users to access the discover page.",
1043
1195
  type: "boolean",
1044
1196
  },
1197
+ {
1198
+ slug: "skills_welcome_tagline",
1199
+ label: "Welcome Tagline",
1200
+ defaultValue: "Pick up where you left off or learn something new.",
1201
+ description: "Tagline displayed in the welcome section of the LMS platform.",
1202
+ type: "string",
1203
+ },
1045
1204
  /* {
1046
1205
  slug: "enable_sidebar_ai_mentor_display",
1047
1206
  label: "Sidebar mentorAI Display",
@@ -1285,103 +1444,6 @@ const advancedTabs = Object.keys(advancedTabsProperties).map((tab) => {
1285
1444
  });
1286
1445
  const translatePrompt = (language) => `Please translate the summarized content into ${language}`;
1287
1446
 
1288
- const MENTOR_CHAT_DOCUMENTS_EXTENSIONS = [
1289
- // Media types
1290
- "video/*",
1291
- "audio/*",
1292
- "image/*",
1293
- // Document types
1294
- ".docx",
1295
- ".xlsx",
1296
- ".pptx",
1297
- ".csv",
1298
- ".md",
1299
- ".txt",
1300
- ".pdf",
1301
- ];
1302
- const ANONYMOUS_USERNAME = "anonymous";
1303
- const DEFAULT_DISCLAIMER_CONTENT = `By accessing and using the [ibl.ai](http://ibl.ai/) MentorAI platform (“Platform”), you agree to the following terms. The Platform provides AI-powered mentorship and educational support. You understand that AI responses may contain inaccuracies, and you are responsible for independently verifying any information before relying on it for academic, professional, or personal decisions. Do not input confidential, sensitive, or personally identifiable information of yourself or others.
1304
- All content, code, and data processed through the Platform remain the property of their respective owners. [ibl.ai](http://ibl.ai/) retains all rights to the Platform’s underlying technology and intellectual property. You are granted a limited, non-exclusive, revocable license to use the Platform for personal or institutional learning purposes only.
1305
- Your use must comply with applicable laws and institutional policies. Misuse—including attempting to bypass security, copy source code, or use the service for unlawful activity—may result in suspension or termination of access. Continued use constitutes acceptance of these terms.`;
1306
- const MAX_INITIAL_WEBSOCKET_CONNECTION_ATTEMPTS = 3;
1307
- const LOCAL_STORAGE_KEYS = {
1308
- CURRENT_TENANT: "current_tenant",
1309
- TENANTS: "tenants",
1310
- REDIRECT_TO: "redirect-to",
1311
- AUTH_TOKEN: "axd_token",
1312
- TOKEN_EXPIRY: "axd_token_expires",
1313
- USER_DATA: "userData",
1314
- USER_TENANTS: "tenants",
1315
- VISITING_TENANT: "visiting_tenant",
1316
- SESSION_ID: "session_id",
1317
- EDX_TOKEN_KEY: "edx_jwt_token",
1318
- DM_TOKEN_KEY: "dm_token",
1319
- DM_TOKEN_EXPIRES: "dm_token_expires",
1320
- DM_TOKEN_EXPIRY: "dm_token_expires",
1321
- AXD_TOKEN_KEY: "axd_token",
1322
- DEFAULT_TENANT: "tenant",
1323
- MODEL_DOWNLOAD_STATE: "model_download_state",
1324
- MODEL_DOWNLOAD_PROMPT_DISMISSED: "model_download_prompt_dismissed",
1325
- };
1326
- const TOOLS = {
1327
- WEB_SEARCH: "web-search",
1328
- WIKIPEDIA_SEARCH: "wikipedia-search",
1329
- COURSE_CREATION: "course-creation",
1330
- MCP: "mcp",
1331
- IMAGE_GENERATION: "image-generation",
1332
- IBL_PATHWAY_DOCUMENTS_RETRIEVER: "ibl-pathway-documents-retriever",
1333
- TRAINED_DOCUMENTS: "trained-documents",
1334
- IBL_SESSION_DOCUMENTS_RETRIEVER: "ibl-session-documents-retriever",
1335
- PLAYWRIGHT_BROWSER: "playwright-browser",
1336
- HUMAN_SUPPORT: "human-support",
1337
- CODE_INTERPRETER: "code-interpreter",
1338
- DEEP_RESEARCH: "deep-research",
1339
- STUDY_MODE: "study-mode",
1340
- MEMORY: "memory",
1341
- SCREEN_SHARE: "screen-share",
1342
- POWERPOINT: "powerpoint",
1343
- PROMPT: "prompt",
1344
- QUIZ: "quiz",
1345
- RUBRIC: "rubric",
1346
- RESOURCE: "resource",
1347
- LESSON_PLAN: "lesson-plan",
1348
- SYLLABUS: "syllabus",
1349
- CANVAS: "canvas",
1350
- GOOGLE_SLIDES: "google-slides",
1351
- GOOGLE_DOCUMENT: "google-docs",
1352
- };
1353
- // Maps WebSocket tool_call type names to human-readable UI labels
1354
- const TOOL_NAME_MAP = {
1355
- web_search_call: "Searching the web",
1356
- vector_search: "Searching knowledge base",
1357
- calculator: "Calculating",
1358
- file_reader: "Reading file",
1359
- code_executor: "Running code",
1360
- wikipedia: "Searching Wikipedia",
1361
- };
1362
- const REQUIRED_ACTIONS_FOR_GROUPS = {
1363
- NOTIFICATIONS: "Ibl.Notifications/Notification/action",
1364
- };
1365
- const MENTOR_VISIBILITY_VALUES = {
1366
- ADMINISTRATORS: "viewable_by_tenant_admins",
1367
- STUDENTS: "viewable_by_tenant_students",
1368
- ANYONE: "viewable_by_anyone",
1369
- };
1370
- const MENTOR_VISIBILITY = [
1371
- {
1372
- label: "Administrators",
1373
- value: MENTOR_VISIBILITY_VALUES.ADMINISTRATORS,
1374
- },
1375
- {
1376
- label: "Users",
1377
- value: MENTOR_VISIBILITY_VALUES.STUDENTS,
1378
- },
1379
- {
1380
- label: "Anyone",
1381
- value: MENTOR_VISIBILITY_VALUES.ANYONE,
1382
- },
1383
- ];
1384
-
1385
1447
  /**
1386
1448
  * Reads the cached user_nicename from the LOCAL_STORAGE_KEYS.USER_DATA blob.
1387
1449
  */
@@ -9197,29 +9259,6 @@ async function syncAuthToCookies(storageService) {
9197
9259
  console.error("[syncAuthToCookies] Error syncing to cookies:", error);
9198
9260
  }
9199
9261
  }
9200
- function hasNonExpiredAuthToken() {
9201
- const token = window.localStorage.getItem(LOCAL_STORAGE_KEYS.AUTH_TOKEN);
9202
- if (!token) {
9203
- console.log("################### [hasNonExpiredAuthToken] axd token is not defined", token);
9204
- return false;
9205
- }
9206
- const tokenExpiry = window.localStorage.getItem(LOCAL_STORAGE_KEYS.TOKEN_EXPIRY);
9207
- if (!tokenExpiry) {
9208
- console.log("################### [hasNonExpiredAuthToken] axd token expiry is not defined", tokenExpiry);
9209
- return true;
9210
- }
9211
- const expiryDate = new Date(tokenExpiry);
9212
- if (isNaN(expiryDate.getTime())) {
9213
- console.log("################### [hasNonExpiredAuthToken] axd token expiry date", expiryDate);
9214
- return false;
9215
- }
9216
- const currentDate = new Date();
9217
- if (expiryDate <= currentDate) {
9218
- console.log("################### [hasNonExpiredAuthToken] axd token expiry date is less than current date ", expiryDate, currentDate);
9219
- return false;
9220
- }
9221
- return true;
9222
- }
9223
9262
  /**
9224
9263
  * Clear current tenant cookie only (web only)
9225
9264
  * Should be called before tenant switching
@@ -19252,6 +19291,7 @@ exports.isExpo = isExpo;
19252
19291
  exports.isFileAccepted = isFileAccepted;
19253
19292
  exports.isInIframe = isInIframe;
19254
19293
  exports.isJSON = isJSON;
19294
+ exports.isJwtExpired = isJwtExpired;
19255
19295
  exports.isLoggedIn = isLoggedIn;
19256
19296
  exports.isNode = isNode;
19257
19297
  exports.isReactNative = isReactNative;