@modelnex/sdk 0.5.21 → 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
@@ -4457,6 +4457,18 @@ function shouldDiscoverDraftPreview({
4457
4457
  }) {
4458
4458
  return !disabled && !hasPendingPrompt && !isPlaybackActive && !isPreviewDiscoveryInFlight && !isStartingExperience;
4459
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
+ }
4460
4472
  function useExperiencePlaybackController({
4461
4473
  serverUrl,
4462
4474
  commandUrl,
@@ -4480,6 +4492,7 @@ function useExperiencePlaybackController({
4480
4492
  const queuedStartRef = (0, import_react13.useRef)(null);
4481
4493
  const bufferedVoiceInputsRef = (0, import_react13.useRef)([]);
4482
4494
  const previewDiscoveryInFlightRef = (0, import_react13.useRef)(false);
4495
+ const previewSessionRef = (0, import_react13.useRef)(false);
4483
4496
  pendingPromptRef.current = pendingPrompt;
4484
4497
  const playback = useTourPlayback({
4485
4498
  serverUrl,
@@ -4502,6 +4515,9 @@ function useExperiencePlaybackController({
4502
4515
  setPendingPrompt(null);
4503
4516
  pendingPromptRef.current = null;
4504
4517
  setStartingExperienceType(experienceType);
4518
+ if (options?.reviewMode) {
4519
+ previewSessionRef.current = true;
4520
+ }
4505
4521
  if (activeExperienceType !== experienceType) {
4506
4522
  queuedStartRef.current = { tour, experienceType, options };
4507
4523
  setActiveExperienceType(experienceType);
@@ -4606,6 +4622,7 @@ function useExperiencePlaybackController({
4606
4622
  if (!request) return;
4607
4623
  let cancelled = false;
4608
4624
  previewDiscoveryInFlightRef.current = true;
4625
+ previewSessionRef.current = true;
4609
4626
  (async () => {
4610
4627
  try {
4611
4628
  persistActiveDraftPreview({ id: request.tourId, experienceType: request.experienceType });
@@ -4641,9 +4658,16 @@ function useExperiencePlaybackController({
4641
4658
  };
4642
4659
  }, [disabled, playback.isActive, queueExperienceStart, serverUrl, startingExperienceType, toursApiBase, websiteId]);
4643
4660
  (0, import_react13.useEffect)(() => {
4644
- if (disabled) return;
4645
- if (!websiteId || !userProfile) return;
4646
- 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;
4647
4671
  let cancelled = false;
4648
4672
  const checkTours = async () => {
4649
4673
  const toursByExperience = await Promise.all(
@@ -4683,7 +4707,7 @@ function useExperiencePlaybackController({
4683
4707
  cancelled = true;
4684
4708
  clearTimeout(timer);
4685
4709
  };
4686
- }, [disabled, playback.isActive, queueExperienceStart, serverUrl, toursApiBase, userProfile, websiteId]);
4710
+ }, [disabled, playback.isActive, queueExperienceStart, serverUrl, startingExperienceType, toursApiBase, userProfile, websiteId]);
4687
4711
  return {
4688
4712
  activeExperienceType,
4689
4713
  startingExperienceType,
package/dist/index.mjs CHANGED
@@ -4247,6 +4247,18 @@ function shouldDiscoverDraftPreview({
4247
4247
  }) {
4248
4248
  return !disabled && !hasPendingPrompt && !isPlaybackActive && !isPreviewDiscoveryInFlight && !isStartingExperience;
4249
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
+ }
4250
4262
  function useExperiencePlaybackController({
4251
4263
  serverUrl,
4252
4264
  commandUrl,
@@ -4270,6 +4282,7 @@ function useExperiencePlaybackController({
4270
4282
  const queuedStartRef = useRef9(null);
4271
4283
  const bufferedVoiceInputsRef = useRef9([]);
4272
4284
  const previewDiscoveryInFlightRef = useRef9(false);
4285
+ const previewSessionRef = useRef9(false);
4273
4286
  pendingPromptRef.current = pendingPrompt;
4274
4287
  const playback = useTourPlayback({
4275
4288
  serverUrl,
@@ -4292,6 +4305,9 @@ function useExperiencePlaybackController({
4292
4305
  setPendingPrompt(null);
4293
4306
  pendingPromptRef.current = null;
4294
4307
  setStartingExperienceType(experienceType);
4308
+ if (options?.reviewMode) {
4309
+ previewSessionRef.current = true;
4310
+ }
4295
4311
  if (activeExperienceType !== experienceType) {
4296
4312
  queuedStartRef.current = { tour, experienceType, options };
4297
4313
  setActiveExperienceType(experienceType);
@@ -4396,6 +4412,7 @@ function useExperiencePlaybackController({
4396
4412
  if (!request) return;
4397
4413
  let cancelled = false;
4398
4414
  previewDiscoveryInFlightRef.current = true;
4415
+ previewSessionRef.current = true;
4399
4416
  (async () => {
4400
4417
  try {
4401
4418
  persistActiveDraftPreview({ id: request.tourId, experienceType: request.experienceType });
@@ -4431,9 +4448,16 @@ function useExperiencePlaybackController({
4431
4448
  };
4432
4449
  }, [disabled, playback.isActive, queueExperienceStart, serverUrl, startingExperienceType, toursApiBase, websiteId]);
4433
4450
  useEffect12(() => {
4434
- if (disabled) return;
4435
- if (!websiteId || !userProfile) return;
4436
- 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;
4437
4461
  let cancelled = false;
4438
4462
  const checkTours = async () => {
4439
4463
  const toursByExperience = await Promise.all(
@@ -4473,7 +4497,7 @@ function useExperiencePlaybackController({
4473
4497
  cancelled = true;
4474
4498
  clearTimeout(timer);
4475
4499
  };
4476
- }, [disabled, playback.isActive, queueExperienceStart, serverUrl, toursApiBase, userProfile, websiteId]);
4500
+ }, [disabled, playback.isActive, queueExperienceStart, serverUrl, startingExperienceType, toursApiBase, userProfile, websiteId]);
4477
4501
  return {
4478
4502
  activeExperienceType,
4479
4503
  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.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",