@modelnex/sdk 0.5.21 → 0.5.23

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
@@ -2460,6 +2460,7 @@ var import_react13 = require("react");
2460
2460
 
2461
2461
  // src/utils/draftPreview.ts
2462
2462
  var ACTIVE_DRAFT_PREVIEW_STORAGE_KEY = "modelnex:active-draft-preview";
2463
+ var PREVIEW_SESSION_SUPPRESSION_STORAGE_KEY = "modelnex:preview-session-suppressed";
2463
2464
  function getPreviewQueryParamName(experienceType) {
2464
2465
  return experienceType === "onboarding" ? "modelnex_test_workflow" : "modelnex_test_tour";
2465
2466
  }
@@ -2509,6 +2510,21 @@ function clearActiveDraftPreview(experienceType) {
2509
2510
  } catch {
2510
2511
  }
2511
2512
  }
2513
+ function persistPreviewSessionSuppression() {
2514
+ if (typeof window === "undefined") return;
2515
+ try {
2516
+ window.sessionStorage.setItem(PREVIEW_SESSION_SUPPRESSION_STORAGE_KEY, "true");
2517
+ } catch {
2518
+ }
2519
+ }
2520
+ function readPreviewSessionSuppression() {
2521
+ if (typeof window === "undefined") return false;
2522
+ try {
2523
+ return window.sessionStorage.getItem(PREVIEW_SESSION_SUPPRESSION_STORAGE_KEY) === "true";
2524
+ } catch {
2525
+ return false;
2526
+ }
2527
+ }
2512
2528
 
2513
2529
  // src/utils/tourDiscovery.ts
2514
2530
  async function fetchTours(serverUrl, toursApiBase, websiteId, userType, userId, experienceType = "tour") {
@@ -4457,6 +4473,18 @@ function shouldDiscoverDraftPreview({
4457
4473
  }) {
4458
4474
  return !disabled && !hasPendingPrompt && !isPlaybackActive && !isPreviewDiscoveryInFlight && !isStartingExperience;
4459
4475
  }
4476
+ function shouldDiscoverEligibleTours({
4477
+ disabled,
4478
+ hasPendingPrompt,
4479
+ hasPreviewSession,
4480
+ isPlaybackActive,
4481
+ isPreviewDiscoveryInFlight,
4482
+ isStartingExperience,
4483
+ hasUserProfile,
4484
+ hasWebsiteId
4485
+ }) {
4486
+ return !disabled && !hasPendingPrompt && !hasPreviewSession && !isPlaybackActive && !isPreviewDiscoveryInFlight && !isStartingExperience && hasUserProfile && hasWebsiteId;
4487
+ }
4460
4488
  function useExperiencePlaybackController({
4461
4489
  serverUrl,
4462
4490
  commandUrl,
@@ -4480,6 +4508,7 @@ function useExperiencePlaybackController({
4480
4508
  const queuedStartRef = (0, import_react13.useRef)(null);
4481
4509
  const bufferedVoiceInputsRef = (0, import_react13.useRef)([]);
4482
4510
  const previewDiscoveryInFlightRef = (0, import_react13.useRef)(false);
4511
+ const previewSessionRef = (0, import_react13.useRef)(readPreviewSessionSuppression());
4483
4512
  pendingPromptRef.current = pendingPrompt;
4484
4513
  const playback = useTourPlayback({
4485
4514
  serverUrl,
@@ -4502,6 +4531,10 @@ function useExperiencePlaybackController({
4502
4531
  setPendingPrompt(null);
4503
4532
  pendingPromptRef.current = null;
4504
4533
  setStartingExperienceType(experienceType);
4534
+ if (options?.reviewMode) {
4535
+ previewSessionRef.current = true;
4536
+ persistPreviewSessionSuppression();
4537
+ }
4505
4538
  if (activeExperienceType !== experienceType) {
4506
4539
  queuedStartRef.current = { tour, experienceType, options };
4507
4540
  setActiveExperienceType(experienceType);
@@ -4606,6 +4639,8 @@ function useExperiencePlaybackController({
4606
4639
  if (!request) return;
4607
4640
  let cancelled = false;
4608
4641
  previewDiscoveryInFlightRef.current = true;
4642
+ previewSessionRef.current = true;
4643
+ persistPreviewSessionSuppression();
4609
4644
  (async () => {
4610
4645
  try {
4611
4646
  persistActiveDraftPreview({ id: request.tourId, experienceType: request.experienceType });
@@ -4641,9 +4676,16 @@ function useExperiencePlaybackController({
4641
4676
  };
4642
4677
  }, [disabled, playback.isActive, queueExperienceStart, serverUrl, startingExperienceType, toursApiBase, websiteId]);
4643
4678
  (0, import_react13.useEffect)(() => {
4644
- if (disabled) return;
4645
- if (!websiteId || !userProfile) return;
4646
- if (playback.isActive || pendingPromptRef.current || previewDiscoveryInFlightRef.current) return;
4679
+ if (!shouldDiscoverEligibleTours({
4680
+ disabled,
4681
+ hasPendingPrompt: Boolean(pendingPromptRef.current),
4682
+ hasPreviewSession: previewSessionRef.current,
4683
+ isPlaybackActive: playback.isActive,
4684
+ isPreviewDiscoveryInFlight: previewDiscoveryInFlightRef.current,
4685
+ isStartingExperience: startingExperienceType !== null,
4686
+ hasUserProfile: Boolean(userProfile),
4687
+ hasWebsiteId: Boolean(websiteId)
4688
+ })) return;
4647
4689
  let cancelled = false;
4648
4690
  const checkTours = async () => {
4649
4691
  const toursByExperience = await Promise.all(
@@ -4683,7 +4725,7 @@ function useExperiencePlaybackController({
4683
4725
  cancelled = true;
4684
4726
  clearTimeout(timer);
4685
4727
  };
4686
- }, [disabled, playback.isActive, queueExperienceStart, serverUrl, toursApiBase, userProfile, websiteId]);
4728
+ }, [disabled, playback.isActive, queueExperienceStart, serverUrl, startingExperienceType, toursApiBase, userProfile, websiteId]);
4687
4729
  return {
4688
4730
  activeExperienceType,
4689
4731
  startingExperienceType,
package/dist/index.mjs CHANGED
@@ -2250,6 +2250,7 @@ import { useCallback as useCallback8, useEffect as useEffect12, useRef as useRef
2250
2250
 
2251
2251
  // src/utils/draftPreview.ts
2252
2252
  var ACTIVE_DRAFT_PREVIEW_STORAGE_KEY = "modelnex:active-draft-preview";
2253
+ var PREVIEW_SESSION_SUPPRESSION_STORAGE_KEY = "modelnex:preview-session-suppressed";
2253
2254
  function getPreviewQueryParamName(experienceType) {
2254
2255
  return experienceType === "onboarding" ? "modelnex_test_workflow" : "modelnex_test_tour";
2255
2256
  }
@@ -2299,6 +2300,21 @@ function clearActiveDraftPreview(experienceType) {
2299
2300
  } catch {
2300
2301
  }
2301
2302
  }
2303
+ function persistPreviewSessionSuppression() {
2304
+ if (typeof window === "undefined") return;
2305
+ try {
2306
+ window.sessionStorage.setItem(PREVIEW_SESSION_SUPPRESSION_STORAGE_KEY, "true");
2307
+ } catch {
2308
+ }
2309
+ }
2310
+ function readPreviewSessionSuppression() {
2311
+ if (typeof window === "undefined") return false;
2312
+ try {
2313
+ return window.sessionStorage.getItem(PREVIEW_SESSION_SUPPRESSION_STORAGE_KEY) === "true";
2314
+ } catch {
2315
+ return false;
2316
+ }
2317
+ }
2302
2318
 
2303
2319
  // src/utils/tourDiscovery.ts
2304
2320
  async function fetchTours(serverUrl, toursApiBase, websiteId, userType, userId, experienceType = "tour") {
@@ -4247,6 +4263,18 @@ function shouldDiscoverDraftPreview({
4247
4263
  }) {
4248
4264
  return !disabled && !hasPendingPrompt && !isPlaybackActive && !isPreviewDiscoveryInFlight && !isStartingExperience;
4249
4265
  }
4266
+ function shouldDiscoverEligibleTours({
4267
+ disabled,
4268
+ hasPendingPrompt,
4269
+ hasPreviewSession,
4270
+ isPlaybackActive,
4271
+ isPreviewDiscoveryInFlight,
4272
+ isStartingExperience,
4273
+ hasUserProfile,
4274
+ hasWebsiteId
4275
+ }) {
4276
+ return !disabled && !hasPendingPrompt && !hasPreviewSession && !isPlaybackActive && !isPreviewDiscoveryInFlight && !isStartingExperience && hasUserProfile && hasWebsiteId;
4277
+ }
4250
4278
  function useExperiencePlaybackController({
4251
4279
  serverUrl,
4252
4280
  commandUrl,
@@ -4270,6 +4298,7 @@ function useExperiencePlaybackController({
4270
4298
  const queuedStartRef = useRef9(null);
4271
4299
  const bufferedVoiceInputsRef = useRef9([]);
4272
4300
  const previewDiscoveryInFlightRef = useRef9(false);
4301
+ const previewSessionRef = useRef9(readPreviewSessionSuppression());
4273
4302
  pendingPromptRef.current = pendingPrompt;
4274
4303
  const playback = useTourPlayback({
4275
4304
  serverUrl,
@@ -4292,6 +4321,10 @@ function useExperiencePlaybackController({
4292
4321
  setPendingPrompt(null);
4293
4322
  pendingPromptRef.current = null;
4294
4323
  setStartingExperienceType(experienceType);
4324
+ if (options?.reviewMode) {
4325
+ previewSessionRef.current = true;
4326
+ persistPreviewSessionSuppression();
4327
+ }
4295
4328
  if (activeExperienceType !== experienceType) {
4296
4329
  queuedStartRef.current = { tour, experienceType, options };
4297
4330
  setActiveExperienceType(experienceType);
@@ -4396,6 +4429,8 @@ function useExperiencePlaybackController({
4396
4429
  if (!request) return;
4397
4430
  let cancelled = false;
4398
4431
  previewDiscoveryInFlightRef.current = true;
4432
+ previewSessionRef.current = true;
4433
+ persistPreviewSessionSuppression();
4399
4434
  (async () => {
4400
4435
  try {
4401
4436
  persistActiveDraftPreview({ id: request.tourId, experienceType: request.experienceType });
@@ -4431,9 +4466,16 @@ function useExperiencePlaybackController({
4431
4466
  };
4432
4467
  }, [disabled, playback.isActive, queueExperienceStart, serverUrl, startingExperienceType, toursApiBase, websiteId]);
4433
4468
  useEffect12(() => {
4434
- if (disabled) return;
4435
- if (!websiteId || !userProfile) return;
4436
- if (playback.isActive || pendingPromptRef.current || previewDiscoveryInFlightRef.current) return;
4469
+ if (!shouldDiscoverEligibleTours({
4470
+ disabled,
4471
+ hasPendingPrompt: Boolean(pendingPromptRef.current),
4472
+ hasPreviewSession: previewSessionRef.current,
4473
+ isPlaybackActive: playback.isActive,
4474
+ isPreviewDiscoveryInFlight: previewDiscoveryInFlightRef.current,
4475
+ isStartingExperience: startingExperienceType !== null,
4476
+ hasUserProfile: Boolean(userProfile),
4477
+ hasWebsiteId: Boolean(websiteId)
4478
+ })) return;
4437
4479
  let cancelled = false;
4438
4480
  const checkTours = async () => {
4439
4481
  const toursByExperience = await Promise.all(
@@ -4473,7 +4515,7 @@ function useExperiencePlaybackController({
4473
4515
  cancelled = true;
4474
4516
  clearTimeout(timer);
4475
4517
  };
4476
- }, [disabled, playback.isActive, queueExperienceStart, serverUrl, toursApiBase, userProfile, websiteId]);
4518
+ }, [disabled, playback.isActive, queueExperienceStart, serverUrl, startingExperienceType, toursApiBase, userProfile, websiteId]);
4477
4519
  return {
4478
4520
  activeExperienceType,
4479
4521
  startingExperienceType,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modelnex/sdk",
3
- "version": "0.5.21",
3
+ "version": "0.5.23",
4
4
  "description": "React SDK for natural language control of web apps via AI agents",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -20,6 +20,15 @@
20
20
  "dist",
21
21
  "README.md"
22
22
  ],
23
+ "scripts": {
24
+ "prepublishOnly": "npm run build",
25
+ "build": "npm exec -- tsup src/index.ts --format cjs,esm --dts",
26
+ "dev": "npm exec -- tsup src/index.ts --format cjs,esm --watch --dts",
27
+ "lint": "eslint src/",
28
+ "test": "npm run build && node --test tests/*.test.js",
29
+ "test:ci": "npm run test && npm run test:unit",
30
+ "test:unit": "node --import tsx --test tests/*.test.ts"
31
+ },
23
32
  "peerDependencies": {
24
33
  "react": ">=17.0.0",
25
34
  "react-dom": ">=17.0.0",
@@ -58,13 +67,5 @@
58
67
  "bugs": {
59
68
  "url": "https://github.com/sharunaraksha/modelnex-sdk/issues"
60
69
  },
61
- "homepage": "https://github.com/sharunaraksha/modelnex-sdk#readme",
62
- "scripts": {
63
- "build": "npm exec -- tsup src/index.ts --format cjs,esm --dts",
64
- "dev": "npm exec -- tsup src/index.ts --format cjs,esm --watch --dts",
65
- "lint": "eslint src/",
66
- "test": "npm run build && node --test tests/*.test.js",
67
- "test:ci": "npm run test && npm run test:unit",
68
- "test:unit": "node --import tsx --test tests/*.test.ts"
69
- }
70
- }
70
+ "homepage": "https://github.com/sharunaraksha/modelnex-sdk#readme"
71
+ }