@modelnex/sdk 0.5.20 → 0.5.22

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
@@ -4448,6 +4448,27 @@ function useTourPlayback({
4448
4448
 
4449
4449
  // src/hooks/useExperiencePlaybackController.ts
4450
4450
  var EXPERIENCE_PRIORITY = ["onboarding", "tour"];
4451
+ function shouldDiscoverDraftPreview({
4452
+ disabled,
4453
+ hasPendingPrompt,
4454
+ isPlaybackActive,
4455
+ isPreviewDiscoveryInFlight,
4456
+ isStartingExperience
4457
+ }) {
4458
+ return !disabled && !hasPendingPrompt && !isPlaybackActive && !isPreviewDiscoveryInFlight && !isStartingExperience;
4459
+ }
4460
+ function shouldDiscoverEligibleTours({
4461
+ disabled,
4462
+ hasPendingPrompt,
4463
+ hasPreviewSession,
4464
+ isPlaybackActive,
4465
+ isPreviewDiscoveryInFlight,
4466
+ isStartingExperience,
4467
+ hasUserProfile,
4468
+ hasWebsiteId
4469
+ }) {
4470
+ return !disabled && !hasPendingPrompt && !hasPreviewSession && !isPlaybackActive && !isPreviewDiscoveryInFlight && !isStartingExperience && hasUserProfile && hasWebsiteId;
4471
+ }
4451
4472
  function useExperiencePlaybackController({
4452
4473
  serverUrl,
4453
4474
  commandUrl,
@@ -4471,6 +4492,7 @@ function useExperiencePlaybackController({
4471
4492
  const queuedStartRef = (0, import_react13.useRef)(null);
4472
4493
  const bufferedVoiceInputsRef = (0, import_react13.useRef)([]);
4473
4494
  const previewDiscoveryInFlightRef = (0, import_react13.useRef)(false);
4495
+ const previewSessionRef = (0, import_react13.useRef)(false);
4474
4496
  pendingPromptRef.current = pendingPrompt;
4475
4497
  const playback = useTourPlayback({
4476
4498
  serverUrl,
@@ -4493,6 +4515,9 @@ function useExperiencePlaybackController({
4493
4515
  setPendingPrompt(null);
4494
4516
  pendingPromptRef.current = null;
4495
4517
  setStartingExperienceType(experienceType);
4518
+ if (options?.reviewMode) {
4519
+ previewSessionRef.current = true;
4520
+ }
4496
4521
  if (activeExperienceType !== experienceType) {
4497
4522
  queuedStartRef.current = { tour, experienceType, options };
4498
4523
  setActiveExperienceType(experienceType);
@@ -4567,9 +4592,14 @@ function useExperiencePlaybackController({
4567
4592
  readyInputs.forEach((item) => playback.handleVoiceInput(item.transcript));
4568
4593
  }, [activeExperienceType, playback]);
4569
4594
  (0, import_react13.useEffect)(() => {
4570
- if (disabled) return;
4595
+ if (!shouldDiscoverDraftPreview({
4596
+ disabled,
4597
+ hasPendingPrompt: Boolean(pendingPromptRef.current),
4598
+ isPlaybackActive: playback.isActive,
4599
+ isPreviewDiscoveryInFlight: previewDiscoveryInFlightRef.current,
4600
+ isStartingExperience: startingExperienceType !== null
4601
+ })) return;
4571
4602
  if (typeof window === "undefined") return;
4572
- if (previewDiscoveryInFlightRef.current) return;
4573
4603
  const params = new URLSearchParams(window.location.search);
4574
4604
  const activeDraftPreview = readActiveDraftPreview();
4575
4605
  const previewRequests = [];
@@ -4592,6 +4622,7 @@ function useExperiencePlaybackController({
4592
4622
  if (!request) return;
4593
4623
  let cancelled = false;
4594
4624
  previewDiscoveryInFlightRef.current = true;
4625
+ previewSessionRef.current = true;
4595
4626
  (async () => {
4596
4627
  try {
4597
4628
  persistActiveDraftPreview({ id: request.tourId, experienceType: request.experienceType });
@@ -4625,11 +4656,18 @@ function useExperiencePlaybackController({
4625
4656
  cancelled = true;
4626
4657
  previewDiscoveryInFlightRef.current = false;
4627
4658
  };
4628
- }, [disabled, queueExperienceStart, serverUrl, toursApiBase, websiteId]);
4659
+ }, [disabled, playback.isActive, queueExperienceStart, serverUrl, startingExperienceType, toursApiBase, websiteId]);
4629
4660
  (0, import_react13.useEffect)(() => {
4630
- if (disabled) return;
4631
- if (!websiteId || !userProfile) return;
4632
- if (playback.isActive || pendingPromptRef.current || previewDiscoveryInFlightRef.current) return;
4661
+ if (!shouldDiscoverEligibleTours({
4662
+ disabled,
4663
+ hasPendingPrompt: Boolean(pendingPromptRef.current),
4664
+ hasPreviewSession: previewSessionRef.current,
4665
+ isPlaybackActive: playback.isActive,
4666
+ isPreviewDiscoveryInFlight: previewDiscoveryInFlightRef.current,
4667
+ isStartingExperience: startingExperienceType !== null,
4668
+ hasUserProfile: Boolean(userProfile),
4669
+ hasWebsiteId: Boolean(websiteId)
4670
+ })) return;
4633
4671
  let cancelled = false;
4634
4672
  const checkTours = async () => {
4635
4673
  const toursByExperience = await Promise.all(
@@ -4669,7 +4707,7 @@ function useExperiencePlaybackController({
4669
4707
  cancelled = true;
4670
4708
  clearTimeout(timer);
4671
4709
  };
4672
- }, [disabled, playback.isActive, queueExperienceStart, serverUrl, toursApiBase, userProfile, websiteId]);
4710
+ }, [disabled, playback.isActive, queueExperienceStart, serverUrl, startingExperienceType, toursApiBase, userProfile, websiteId]);
4673
4711
  return {
4674
4712
  activeExperienceType,
4675
4713
  startingExperienceType,
package/dist/index.mjs CHANGED
@@ -4238,6 +4238,27 @@ function useTourPlayback({
4238
4238
 
4239
4239
  // src/hooks/useExperiencePlaybackController.ts
4240
4240
  var EXPERIENCE_PRIORITY = ["onboarding", "tour"];
4241
+ function shouldDiscoverDraftPreview({
4242
+ disabled,
4243
+ hasPendingPrompt,
4244
+ isPlaybackActive,
4245
+ isPreviewDiscoveryInFlight,
4246
+ isStartingExperience
4247
+ }) {
4248
+ return !disabled && !hasPendingPrompt && !isPlaybackActive && !isPreviewDiscoveryInFlight && !isStartingExperience;
4249
+ }
4250
+ function shouldDiscoverEligibleTours({
4251
+ disabled,
4252
+ hasPendingPrompt,
4253
+ hasPreviewSession,
4254
+ isPlaybackActive,
4255
+ isPreviewDiscoveryInFlight,
4256
+ isStartingExperience,
4257
+ hasUserProfile,
4258
+ hasWebsiteId
4259
+ }) {
4260
+ return !disabled && !hasPendingPrompt && !hasPreviewSession && !isPlaybackActive && !isPreviewDiscoveryInFlight && !isStartingExperience && hasUserProfile && hasWebsiteId;
4261
+ }
4241
4262
  function useExperiencePlaybackController({
4242
4263
  serverUrl,
4243
4264
  commandUrl,
@@ -4261,6 +4282,7 @@ function useExperiencePlaybackController({
4261
4282
  const queuedStartRef = useRef9(null);
4262
4283
  const bufferedVoiceInputsRef = useRef9([]);
4263
4284
  const previewDiscoveryInFlightRef = useRef9(false);
4285
+ const previewSessionRef = useRef9(false);
4264
4286
  pendingPromptRef.current = pendingPrompt;
4265
4287
  const playback = useTourPlayback({
4266
4288
  serverUrl,
@@ -4283,6 +4305,9 @@ function useExperiencePlaybackController({
4283
4305
  setPendingPrompt(null);
4284
4306
  pendingPromptRef.current = null;
4285
4307
  setStartingExperienceType(experienceType);
4308
+ if (options?.reviewMode) {
4309
+ previewSessionRef.current = true;
4310
+ }
4286
4311
  if (activeExperienceType !== experienceType) {
4287
4312
  queuedStartRef.current = { tour, experienceType, options };
4288
4313
  setActiveExperienceType(experienceType);
@@ -4357,9 +4382,14 @@ function useExperiencePlaybackController({
4357
4382
  readyInputs.forEach((item) => playback.handleVoiceInput(item.transcript));
4358
4383
  }, [activeExperienceType, playback]);
4359
4384
  useEffect12(() => {
4360
- if (disabled) return;
4385
+ if (!shouldDiscoverDraftPreview({
4386
+ disabled,
4387
+ hasPendingPrompt: Boolean(pendingPromptRef.current),
4388
+ isPlaybackActive: playback.isActive,
4389
+ isPreviewDiscoveryInFlight: previewDiscoveryInFlightRef.current,
4390
+ isStartingExperience: startingExperienceType !== null
4391
+ })) return;
4361
4392
  if (typeof window === "undefined") return;
4362
- if (previewDiscoveryInFlightRef.current) return;
4363
4393
  const params = new URLSearchParams(window.location.search);
4364
4394
  const activeDraftPreview = readActiveDraftPreview();
4365
4395
  const previewRequests = [];
@@ -4382,6 +4412,7 @@ function useExperiencePlaybackController({
4382
4412
  if (!request) return;
4383
4413
  let cancelled = false;
4384
4414
  previewDiscoveryInFlightRef.current = true;
4415
+ previewSessionRef.current = true;
4385
4416
  (async () => {
4386
4417
  try {
4387
4418
  persistActiveDraftPreview({ id: request.tourId, experienceType: request.experienceType });
@@ -4415,11 +4446,18 @@ function useExperiencePlaybackController({
4415
4446
  cancelled = true;
4416
4447
  previewDiscoveryInFlightRef.current = false;
4417
4448
  };
4418
- }, [disabled, queueExperienceStart, serverUrl, toursApiBase, websiteId]);
4449
+ }, [disabled, playback.isActive, queueExperienceStart, serverUrl, startingExperienceType, toursApiBase, websiteId]);
4419
4450
  useEffect12(() => {
4420
- if (disabled) return;
4421
- if (!websiteId || !userProfile) return;
4422
- if (playback.isActive || pendingPromptRef.current || previewDiscoveryInFlightRef.current) return;
4451
+ if (!shouldDiscoverEligibleTours({
4452
+ disabled,
4453
+ hasPendingPrompt: Boolean(pendingPromptRef.current),
4454
+ hasPreviewSession: previewSessionRef.current,
4455
+ isPlaybackActive: playback.isActive,
4456
+ isPreviewDiscoveryInFlight: previewDiscoveryInFlightRef.current,
4457
+ isStartingExperience: startingExperienceType !== null,
4458
+ hasUserProfile: Boolean(userProfile),
4459
+ hasWebsiteId: Boolean(websiteId)
4460
+ })) return;
4423
4461
  let cancelled = false;
4424
4462
  const checkTours = async () => {
4425
4463
  const toursByExperience = await Promise.all(
@@ -4459,7 +4497,7 @@ function useExperiencePlaybackController({
4459
4497
  cancelled = true;
4460
4498
  clearTimeout(timer);
4461
4499
  };
4462
- }, [disabled, playback.isActive, queueExperienceStart, serverUrl, toursApiBase, userProfile, websiteId]);
4500
+ }, [disabled, playback.isActive, queueExperienceStart, serverUrl, startingExperienceType, toursApiBase, userProfile, websiteId]);
4463
4501
  return {
4464
4502
  activeExperienceType,
4465
4503
  startingExperienceType,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modelnex/sdk",
3
- "version": "0.5.20",
3
+ "version": "0.5.22",
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",