@modelnex/sdk 0.5.47 → 0.5.49

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
@@ -4572,16 +4572,23 @@ function useTourPlayback({
4572
4572
  claimedPlaybackOwnerKeyRef.current = null;
4573
4573
  }, []);
4574
4574
  const emitTourInit = (0, import_react12.useCallback)((socket, currentWebsiteId, profile) => {
4575
- if (!currentWebsiteId || !profile?.type) return;
4576
4575
  const persistedRunId = runIdRef.current ?? readPersistedActiveTourSession()?.runId ?? null;
4577
- const payload = {
4578
- websiteId: currentWebsiteId,
4579
- userId: profile.userId,
4580
- userType: profile.type
4581
- };
4576
+ const payload = {};
4577
+ if (currentWebsiteId) {
4578
+ payload.websiteId = currentWebsiteId;
4579
+ }
4580
+ if (profile?.userId) {
4581
+ payload.userId = profile.userId;
4582
+ }
4583
+ if (profile?.type) {
4584
+ payload.userType = profile.type;
4585
+ }
4582
4586
  if (typeof persistedRunId === "number") {
4583
4587
  payload.resumeRunId = persistedRunId;
4584
4588
  }
4589
+ if (!payload.resumeRunId && (!payload.websiteId || !payload.userType)) {
4590
+ return;
4591
+ }
4585
4592
  emitSocketEvent(socket, "tour:init", payload);
4586
4593
  }, []);
4587
4594
  (0, import_react12.useEffect)(() => {
@@ -5262,27 +5269,33 @@ function useTourPlayback({
5262
5269
  skipRequestedRef.current = false;
5263
5270
  startRequestedRef.current = false;
5264
5271
  const total = tourData.totalSteps ?? tour?.steps?.length ?? 0;
5272
+ const requestedStepIndex = typeof tourData.currentStepIndex === "number" ? tourData.currentStepIndex : 0;
5273
+ const clampedStepIndex = Math.max(0, Math.min(requestedStepIndex, Math.max(0, total - 1)));
5265
5274
  isActiveRef.current = true;
5266
5275
  setIsActive(true);
5267
5276
  setActiveTour(tour ?? null);
5268
5277
  tourRef.current = tour ?? null;
5269
5278
  setTotalSteps(total);
5270
- stepIndexRef.current = 0;
5271
- setCurrentStepIndex(0);
5279
+ stepIndexRef.current = clampedStepIndex;
5280
+ setCurrentStepIndex(clampedStepIndex);
5272
5281
  setPlaybackState("intro");
5273
5282
  if (reviewModeRef.current && tour?.id && previewRunIdRef.current) {
5274
5283
  void logPreviewEvent(serverUrl, toursApiBaseRef.current, tour.id, previewRunIdRef.current, websiteId, {
5275
- stepOrder: 0,
5284
+ stepOrder: clampedStepIndex,
5276
5285
  eventType: "tour_started",
5277
5286
  payload: {
5278
5287
  totalSteps: total,
5279
- source: "sdk_test_preview"
5288
+ source: "sdk_test_preview",
5289
+ resumed: Boolean(tourData.resumed)
5280
5290
  },
5281
- currentStepOrder: 0
5291
+ currentStepOrder: clampedStepIndex
5282
5292
  });
5283
5293
  } else if (tour?.id && userProfile?.userId) {
5284
5294
  void recordTourEvent(serverUrl, toursApiBaseRef.current, tour.id, userProfile.userId, "started", websiteId);
5285
5295
  }
5296
+ if (tour && total > 0) {
5297
+ onStepChangeRef.current?.(clampedStepIndex, total, tour);
5298
+ }
5286
5299
  try {
5287
5300
  const { generateMinifiedAOM: generateMinifiedAOM2 } = await Promise.resolve().then(() => (init_aom(), aom_exports));
5288
5301
  const aom = generateMinifiedAOM2();
package/dist/index.mjs CHANGED
@@ -3743,16 +3743,23 @@ function useTourPlayback({
3743
3743
  claimedPlaybackOwnerKeyRef.current = null;
3744
3744
  }, []);
3745
3745
  const emitTourInit = useCallback6((socket, currentWebsiteId, profile) => {
3746
- if (!currentWebsiteId || !profile?.type) return;
3747
3746
  const persistedRunId = runIdRef.current ?? readPersistedActiveTourSession()?.runId ?? null;
3748
- const payload = {
3749
- websiteId: currentWebsiteId,
3750
- userId: profile.userId,
3751
- userType: profile.type
3752
- };
3747
+ const payload = {};
3748
+ if (currentWebsiteId) {
3749
+ payload.websiteId = currentWebsiteId;
3750
+ }
3751
+ if (profile?.userId) {
3752
+ payload.userId = profile.userId;
3753
+ }
3754
+ if (profile?.type) {
3755
+ payload.userType = profile.type;
3756
+ }
3753
3757
  if (typeof persistedRunId === "number") {
3754
3758
  payload.resumeRunId = persistedRunId;
3755
3759
  }
3760
+ if (!payload.resumeRunId && (!payload.websiteId || !payload.userType)) {
3761
+ return;
3762
+ }
3756
3763
  emitSocketEvent(socket, "tour:init", payload);
3757
3764
  }, []);
3758
3765
  useEffect10(() => {
@@ -4433,27 +4440,33 @@ function useTourPlayback({
4433
4440
  skipRequestedRef.current = false;
4434
4441
  startRequestedRef.current = false;
4435
4442
  const total = tourData.totalSteps ?? tour?.steps?.length ?? 0;
4443
+ const requestedStepIndex = typeof tourData.currentStepIndex === "number" ? tourData.currentStepIndex : 0;
4444
+ const clampedStepIndex = Math.max(0, Math.min(requestedStepIndex, Math.max(0, total - 1)));
4436
4445
  isActiveRef.current = true;
4437
4446
  setIsActive(true);
4438
4447
  setActiveTour(tour ?? null);
4439
4448
  tourRef.current = tour ?? null;
4440
4449
  setTotalSteps(total);
4441
- stepIndexRef.current = 0;
4442
- setCurrentStepIndex(0);
4450
+ stepIndexRef.current = clampedStepIndex;
4451
+ setCurrentStepIndex(clampedStepIndex);
4443
4452
  setPlaybackState("intro");
4444
4453
  if (reviewModeRef.current && tour?.id && previewRunIdRef.current) {
4445
4454
  void logPreviewEvent(serverUrl, toursApiBaseRef.current, tour.id, previewRunIdRef.current, websiteId, {
4446
- stepOrder: 0,
4455
+ stepOrder: clampedStepIndex,
4447
4456
  eventType: "tour_started",
4448
4457
  payload: {
4449
4458
  totalSteps: total,
4450
- source: "sdk_test_preview"
4459
+ source: "sdk_test_preview",
4460
+ resumed: Boolean(tourData.resumed)
4451
4461
  },
4452
- currentStepOrder: 0
4462
+ currentStepOrder: clampedStepIndex
4453
4463
  });
4454
4464
  } else if (tour?.id && userProfile?.userId) {
4455
4465
  void recordTourEvent(serverUrl, toursApiBaseRef.current, tour.id, userProfile.userId, "started", websiteId);
4456
4466
  }
4467
+ if (tour && total > 0) {
4468
+ onStepChangeRef.current?.(clampedStepIndex, total, tour);
4469
+ }
4457
4470
  try {
4458
4471
  const { generateMinifiedAOM: generateMinifiedAOM2 } = await import("./aom-SP2LMWQI.mjs");
4459
4472
  const aom = generateMinifiedAOM2();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modelnex/sdk",
3
- "version": "0.5.47",
3
+ "version": "0.5.49",
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",