@modelnex/sdk 0.5.48 → 0.5.50

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
@@ -4546,6 +4546,7 @@ function useTourPlayback({
4546
4546
  const runIdRef = (0, import_react12.useRef)(initialPersistedTourSessionRef.current?.runId ?? null);
4547
4547
  const turnIdRef = (0, import_react12.useRef)(null);
4548
4548
  const startRequestedRef = (0, import_react12.useRef)(false);
4549
+ const serverStateRef = (0, import_react12.useRef)(null);
4549
4550
  const playbackOwnerIdRef = (0, import_react12.useRef)(`playback-owner-${Math.random().toString(36).slice(2, 10)}`);
4550
4551
  const claimedPlaybackOwnerKeyRef = (0, import_react12.useRef)(null);
4551
4552
  const socketRef = (0, import_react12.useRef)(null);
@@ -4565,6 +4566,7 @@ function useTourPlayback({
4565
4566
  toursApiBaseRef.current = toursApiBase;
4566
4567
  pendingTourRef.current = pendingTour;
4567
4568
  showCaptionsRef.current = showCaptions;
4569
+ serverStateRef.current = serverState;
4568
4570
  const releasePlaybackOwnership = (0, import_react12.useCallback)(() => {
4569
4571
  const claimedKey = claimedPlaybackOwnerKeyRef.current;
4570
4572
  if (!claimedKey) return;
@@ -4572,16 +4574,23 @@ function useTourPlayback({
4572
4574
  claimedPlaybackOwnerKeyRef.current = null;
4573
4575
  }, []);
4574
4576
  const emitTourInit = (0, import_react12.useCallback)((socket, currentWebsiteId, profile) => {
4575
- if (!currentWebsiteId || !profile?.type) return;
4576
4577
  const persistedRunId = runIdRef.current ?? readPersistedActiveTourSession()?.runId ?? null;
4577
- const payload = {
4578
- websiteId: currentWebsiteId,
4579
- userId: profile.userId,
4580
- userType: profile.type
4581
- };
4578
+ const payload = {};
4579
+ if (currentWebsiteId) {
4580
+ payload.websiteId = currentWebsiteId;
4581
+ }
4582
+ if (profile?.userId) {
4583
+ payload.userId = profile.userId;
4584
+ }
4585
+ if (profile?.type) {
4586
+ payload.userType = profile.type;
4587
+ }
4582
4588
  if (typeof persistedRunId === "number") {
4583
4589
  payload.resumeRunId = persistedRunId;
4584
4590
  }
4591
+ if (!payload.resumeRunId && (!payload.websiteId || !payload.userType)) {
4592
+ return;
4593
+ }
4585
4594
  emitSocketEvent(socket, "tour:init", payload);
4586
4595
  }, []);
4587
4596
  (0, import_react12.useEffect)(() => {
@@ -4598,6 +4607,7 @@ function useTourPlayback({
4598
4607
  emitTourInit(socket, currentWebsiteId, profile);
4599
4608
  };
4600
4609
  const handleServerState = (payload) => {
4610
+ serverStateRef.current = payload;
4601
4611
  if (typeof payload?.runId === "number") {
4602
4612
  runIdRef.current = payload.runId;
4603
4613
  }
@@ -5261,6 +5271,9 @@ function useTourPlayback({
5261
5271
  claimedPlaybackOwnerKeyRef.current = ownerKey;
5262
5272
  skipRequestedRef.current = false;
5263
5273
  startRequestedRef.current = false;
5274
+ setPendingTour(null);
5275
+ pendingTourRef.current = null;
5276
+ pendingTourOptionsRef.current = null;
5264
5277
  const total = tourData.totalSteps ?? tour?.steps?.length ?? 0;
5265
5278
  const requestedStepIndex = typeof tourData.currentStepIndex === "number" ? tourData.currentStepIndex : 0;
5266
5279
  const clampedStepIndex = Math.max(0, Math.min(requestedStepIndex, Math.max(0, total - 1)));
@@ -5567,6 +5580,14 @@ function useTourPlayback({
5567
5580
  }, { devMode: devModeRef.current });
5568
5581
  return;
5569
5582
  }
5583
+ if (serverStateRef.current?.isActive && typeof serverStateRef.current?.runId === "number") {
5584
+ emitSdkDebugLog("[TourClient] Ignoring start request because the server already has an active run", {
5585
+ tourId: tour.id,
5586
+ activeRunId: serverStateRef.current.runId,
5587
+ activeStepIndex: serverStateRef.current.stepIndex
5588
+ }, { devMode: devModeRef.current });
5589
+ return;
5590
+ }
5570
5591
  setPendingTour(null);
5571
5592
  pendingTourRef.current = null;
5572
5593
  let retries = 0;
package/dist/index.mjs CHANGED
@@ -3717,6 +3717,7 @@ function useTourPlayback({
3717
3717
  const runIdRef = useRef7(initialPersistedTourSessionRef.current?.runId ?? null);
3718
3718
  const turnIdRef = useRef7(null);
3719
3719
  const startRequestedRef = useRef7(false);
3720
+ const serverStateRef = useRef7(null);
3720
3721
  const playbackOwnerIdRef = useRef7(`playback-owner-${Math.random().toString(36).slice(2, 10)}`);
3721
3722
  const claimedPlaybackOwnerKeyRef = useRef7(null);
3722
3723
  const socketRef = useRef7(null);
@@ -3736,6 +3737,7 @@ function useTourPlayback({
3736
3737
  toursApiBaseRef.current = toursApiBase;
3737
3738
  pendingTourRef.current = pendingTour;
3738
3739
  showCaptionsRef.current = showCaptions;
3740
+ serverStateRef.current = serverState;
3739
3741
  const releasePlaybackOwnership = useCallback6(() => {
3740
3742
  const claimedKey = claimedPlaybackOwnerKeyRef.current;
3741
3743
  if (!claimedKey) return;
@@ -3743,16 +3745,23 @@ function useTourPlayback({
3743
3745
  claimedPlaybackOwnerKeyRef.current = null;
3744
3746
  }, []);
3745
3747
  const emitTourInit = useCallback6((socket, currentWebsiteId, profile) => {
3746
- if (!currentWebsiteId || !profile?.type) return;
3747
3748
  const persistedRunId = runIdRef.current ?? readPersistedActiveTourSession()?.runId ?? null;
3748
- const payload = {
3749
- websiteId: currentWebsiteId,
3750
- userId: profile.userId,
3751
- userType: profile.type
3752
- };
3749
+ const payload = {};
3750
+ if (currentWebsiteId) {
3751
+ payload.websiteId = currentWebsiteId;
3752
+ }
3753
+ if (profile?.userId) {
3754
+ payload.userId = profile.userId;
3755
+ }
3756
+ if (profile?.type) {
3757
+ payload.userType = profile.type;
3758
+ }
3753
3759
  if (typeof persistedRunId === "number") {
3754
3760
  payload.resumeRunId = persistedRunId;
3755
3761
  }
3762
+ if (!payload.resumeRunId && (!payload.websiteId || !payload.userType)) {
3763
+ return;
3764
+ }
3756
3765
  emitSocketEvent(socket, "tour:init", payload);
3757
3766
  }, []);
3758
3767
  useEffect10(() => {
@@ -3769,6 +3778,7 @@ function useTourPlayback({
3769
3778
  emitTourInit(socket, currentWebsiteId, profile);
3770
3779
  };
3771
3780
  const handleServerState = (payload) => {
3781
+ serverStateRef.current = payload;
3772
3782
  if (typeof payload?.runId === "number") {
3773
3783
  runIdRef.current = payload.runId;
3774
3784
  }
@@ -4432,6 +4442,9 @@ function useTourPlayback({
4432
4442
  claimedPlaybackOwnerKeyRef.current = ownerKey;
4433
4443
  skipRequestedRef.current = false;
4434
4444
  startRequestedRef.current = false;
4445
+ setPendingTour(null);
4446
+ pendingTourRef.current = null;
4447
+ pendingTourOptionsRef.current = null;
4435
4448
  const total = tourData.totalSteps ?? tour?.steps?.length ?? 0;
4436
4449
  const requestedStepIndex = typeof tourData.currentStepIndex === "number" ? tourData.currentStepIndex : 0;
4437
4450
  const clampedStepIndex = Math.max(0, Math.min(requestedStepIndex, Math.max(0, total - 1)));
@@ -4738,6 +4751,14 @@ function useTourPlayback({
4738
4751
  }, { devMode: devModeRef.current });
4739
4752
  return;
4740
4753
  }
4754
+ if (serverStateRef.current?.isActive && typeof serverStateRef.current?.runId === "number") {
4755
+ emitSdkDebugLog("[TourClient] Ignoring start request because the server already has an active run", {
4756
+ tourId: tour.id,
4757
+ activeRunId: serverStateRef.current.runId,
4758
+ activeStepIndex: serverStateRef.current.stepIndex
4759
+ }, { devMode: devModeRef.current });
4760
+ return;
4761
+ }
4741
4762
  setPendingTour(null);
4742
4763
  pendingTourRef.current = null;
4743
4764
  let retries = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modelnex/sdk",
3
- "version": "0.5.48",
3
+ "version": "0.5.50",
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",