@modelnex/sdk 0.5.55 → 0.5.59

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
@@ -3939,6 +3939,11 @@ function shouldExecuteTourCommandBatch(isPlaybackActive) {
3939
3939
  function shouldAcceptTourStart(state) {
3940
3940
  return !state.isPlaybackActive && !state.startRequested;
3941
3941
  }
3942
+ function shouldAcceptTourExperienceType(hookType, incomingType, isResumed) {
3943
+ const matchesType = !incomingType || incomingType === hookType;
3944
+ const isCompatibleResumption = isResumed && (hookType === "onboarding" && incomingType === "tour" || hookType === "tour" && incomingType === "onboarding");
3945
+ return matchesType || isCompatibleResumption;
3946
+ }
3942
3947
  function shouldRunTourAutoDiscovery(state) {
3943
3948
  return state.enableAutoDiscovery && !state.disabled && !state.isPlaybackActive && !state.startRequested && !state.hasPendingTour;
3944
3949
  }
@@ -3978,6 +3983,25 @@ function releaseTourPlaybackOwnership(key, ownerId) {
3978
3983
 
3979
3984
  // src/hooks/useTourPlayback.ts
3980
3985
  init_dev_logging();
3986
+ function shouldSuppressCompletedDraftPreview({
3987
+ endingTourId,
3988
+ endingPreviewRunId
3989
+ }) {
3990
+ return Boolean(endingTourId && endingPreviewRunId);
3991
+ }
3992
+ function getCompletedDraftPreviewToSuppress({
3993
+ endingTourId,
3994
+ endingPreviewRunId,
3995
+ experienceType
3996
+ }) {
3997
+ if (!shouldSuppressCompletedDraftPreview({ endingTourId, endingPreviewRunId })) {
3998
+ return null;
3999
+ }
4000
+ return {
4001
+ id: endingTourId,
4002
+ experienceType
4003
+ };
4004
+ }
3981
4005
  function resolveElement(step) {
3982
4006
  const el = step.element;
3983
4007
  if (!el) return null;
@@ -4799,7 +4823,7 @@ function useTourPlayback({
4799
4823
  }
4800
4824
  await waitForUserAction(gateTarget, segment.gate.event);
4801
4825
  }
4802
- if (segmentText && showCaptionsRef.current && reviewModeRef.current) {
4826
+ if (segmentText && showCaptionsRef.current) {
4803
4827
  showCaption(segmentText);
4804
4828
  }
4805
4829
  const nextSegmentText = (segments[index + 1]?.text ?? "").trim();
@@ -4826,7 +4850,7 @@ function useTourPlayback({
4826
4850
  if (params.removeHighlightAtEnd !== false) {
4827
4851
  removeHighlight();
4828
4852
  }
4829
- if (showCaptionsRef.current && reviewModeRef.current) {
4853
+ if (showCaptionsRef.current) {
4830
4854
  removeCaption();
4831
4855
  }
4832
4856
  return !!params.waitForInput;
@@ -4836,7 +4860,7 @@ function useTourPlayback({
4836
4860
  if (!text.trim()) {
4837
4861
  return { result: null };
4838
4862
  }
4839
- if (showCaptionsRef.current && reviewModeRef.current) {
4863
+ if (showCaptionsRef.current) {
4840
4864
  showCaption(text);
4841
4865
  }
4842
4866
  const settlePromise = voice.speak(text, tourRef.current?.voice?.ttsVoice, {
@@ -5265,9 +5289,8 @@ function useTourPlayback({
5265
5289
  }
5266
5290
  const tour = tourData.tourContext ?? tourRef.current;
5267
5291
  const expType = experienceTypeRef.current;
5268
- const matchesType = !tour?.type || tour.type === expType;
5269
- const isCompatibleResumption = !!tourData.resumed && (expType === "onboarding" && tour?.type === "tour" || expType === "tour" && tour?.type === "onboarding");
5270
- if (!matchesType && !isCompatibleResumption) {
5292
+ const isCompatible = shouldAcceptTourExperienceType(expType, tour?.type, !!tourData.resumed);
5293
+ if (!isCompatible) {
5271
5294
  emitSdkDebugLog("[TourClient] Ignoring tour start for mismatched experience type", {
5272
5295
  incomingType: tour?.type,
5273
5296
  hookType: expType,
@@ -5415,10 +5438,10 @@ function useTourPlayback({
5415
5438
  return () => clearTimeout(timer);
5416
5439
  }, [disabled, emitTourInit, websiteId, userProfile?.userId, userProfile?.type]);
5417
5440
  (0, import_react12.useEffect)(() => {
5418
- if (!showCaptions || !isReviewMode) {
5441
+ if (!showCaptions) {
5419
5442
  removeCaption();
5420
5443
  }
5421
- }, [showCaptions, isReviewMode]);
5444
+ }, [showCaptions]);
5422
5445
  (0, import_react12.useEffect)(() => {
5423
5446
  if (!isActiveRef.current) return;
5424
5447
  emitSocketEvent(socketRef.current, "tour:client_state", {
@@ -5544,6 +5567,11 @@ function useTourPlayback({
5544
5567
  const endingTourId = tourRef.current?.id;
5545
5568
  const endingPreviewRunId = previewRunIdRef.current;
5546
5569
  const endingStepOrder = stepIndexRef.current;
5570
+ const completedPreviewDraft = getCompletedDraftPreviewToSuppress({
5571
+ endingTourId,
5572
+ endingPreviewRunId,
5573
+ experienceType
5574
+ });
5547
5575
  isActiveRef.current = false;
5548
5576
  startRequestedRef.current = false;
5549
5577
  releasePlaybackOwnership();
@@ -5553,6 +5581,10 @@ function useTourPlayback({
5553
5581
  runCleanup(pendingManualWaitCleanupRef.current);
5554
5582
  pendingManualWaitCleanupRef.current = null;
5555
5583
  clearPendingManualInputSync();
5584
+ if (completedPreviewDraft) {
5585
+ persistSuppressedDraftPreview(completedPreviewDraft);
5586
+ clearActiveDraftPreview(experienceType);
5587
+ }
5556
5588
  if (!skipRequestedRef.current && userProfile?.userId && tourRef.current) {
5557
5589
  markTourComplete(serverUrl, toursApiBaseRef.current, tourRef.current.id, userProfile.userId, experienceType, websiteId);
5558
5590
  }
@@ -5577,7 +5609,7 @@ function useTourPlayback({
5577
5609
  });
5578
5610
  }
5579
5611
  if (reviewModeRef.current) {
5580
- if (endingTourId) {
5612
+ if (endingTourId && !completedPreviewDraft) {
5581
5613
  persistSuppressedDraftPreview({
5582
5614
  id: endingTourId,
5583
5615
  experienceType
package/dist/index.mjs CHANGED
@@ -3111,6 +3111,11 @@ function shouldExecuteTourCommandBatch(isPlaybackActive) {
3111
3111
  function shouldAcceptTourStart(state) {
3112
3112
  return !state.isPlaybackActive && !state.startRequested;
3113
3113
  }
3114
+ function shouldAcceptTourExperienceType(hookType, incomingType, isResumed) {
3115
+ const matchesType = !incomingType || incomingType === hookType;
3116
+ const isCompatibleResumption = isResumed && (hookType === "onboarding" && incomingType === "tour" || hookType === "tour" && incomingType === "onboarding");
3117
+ return matchesType || isCompatibleResumption;
3118
+ }
3114
3119
  function shouldRunTourAutoDiscovery(state) {
3115
3120
  return state.enableAutoDiscovery && !state.disabled && !state.isPlaybackActive && !state.startRequested && !state.hasPendingTour;
3116
3121
  }
@@ -3149,6 +3154,25 @@ function releaseTourPlaybackOwnership(key, ownerId) {
3149
3154
  }
3150
3155
 
3151
3156
  // src/hooks/useTourPlayback.ts
3157
+ function shouldSuppressCompletedDraftPreview({
3158
+ endingTourId,
3159
+ endingPreviewRunId
3160
+ }) {
3161
+ return Boolean(endingTourId && endingPreviewRunId);
3162
+ }
3163
+ function getCompletedDraftPreviewToSuppress({
3164
+ endingTourId,
3165
+ endingPreviewRunId,
3166
+ experienceType
3167
+ }) {
3168
+ if (!shouldSuppressCompletedDraftPreview({ endingTourId, endingPreviewRunId })) {
3169
+ return null;
3170
+ }
3171
+ return {
3172
+ id: endingTourId,
3173
+ experienceType
3174
+ };
3175
+ }
3152
3176
  function resolveElement(step) {
3153
3177
  const el = step.element;
3154
3178
  if (!el) return null;
@@ -3970,7 +3994,7 @@ function useTourPlayback({
3970
3994
  }
3971
3995
  await waitForUserAction(gateTarget, segment.gate.event);
3972
3996
  }
3973
- if (segmentText && showCaptionsRef.current && reviewModeRef.current) {
3997
+ if (segmentText && showCaptionsRef.current) {
3974
3998
  showCaption(segmentText);
3975
3999
  }
3976
4000
  const nextSegmentText = (segments[index + 1]?.text ?? "").trim();
@@ -3997,7 +4021,7 @@ function useTourPlayback({
3997
4021
  if (params.removeHighlightAtEnd !== false) {
3998
4022
  removeHighlight();
3999
4023
  }
4000
- if (showCaptionsRef.current && reviewModeRef.current) {
4024
+ if (showCaptionsRef.current) {
4001
4025
  removeCaption();
4002
4026
  }
4003
4027
  return !!params.waitForInput;
@@ -4007,7 +4031,7 @@ function useTourPlayback({
4007
4031
  if (!text.trim()) {
4008
4032
  return { result: null };
4009
4033
  }
4010
- if (showCaptionsRef.current && reviewModeRef.current) {
4034
+ if (showCaptionsRef.current) {
4011
4035
  showCaption(text);
4012
4036
  }
4013
4037
  const settlePromise = voice.speak(text, tourRef.current?.voice?.ttsVoice, {
@@ -4436,9 +4460,8 @@ function useTourPlayback({
4436
4460
  }
4437
4461
  const tour = tourData.tourContext ?? tourRef.current;
4438
4462
  const expType = experienceTypeRef.current;
4439
- const matchesType = !tour?.type || tour.type === expType;
4440
- const isCompatibleResumption = !!tourData.resumed && (expType === "onboarding" && tour?.type === "tour" || expType === "tour" && tour?.type === "onboarding");
4441
- if (!matchesType && !isCompatibleResumption) {
4463
+ const isCompatible = shouldAcceptTourExperienceType(expType, tour?.type, !!tourData.resumed);
4464
+ if (!isCompatible) {
4442
4465
  emitSdkDebugLog("[TourClient] Ignoring tour start for mismatched experience type", {
4443
4466
  incomingType: tour?.type,
4444
4467
  hookType: expType,
@@ -4586,10 +4609,10 @@ function useTourPlayback({
4586
4609
  return () => clearTimeout(timer);
4587
4610
  }, [disabled, emitTourInit, websiteId, userProfile?.userId, userProfile?.type]);
4588
4611
  useEffect10(() => {
4589
- if (!showCaptions || !isReviewMode) {
4612
+ if (!showCaptions) {
4590
4613
  removeCaption();
4591
4614
  }
4592
- }, [showCaptions, isReviewMode]);
4615
+ }, [showCaptions]);
4593
4616
  useEffect10(() => {
4594
4617
  if (!isActiveRef.current) return;
4595
4618
  emitSocketEvent(socketRef.current, "tour:client_state", {
@@ -4715,6 +4738,11 @@ function useTourPlayback({
4715
4738
  const endingTourId = tourRef.current?.id;
4716
4739
  const endingPreviewRunId = previewRunIdRef.current;
4717
4740
  const endingStepOrder = stepIndexRef.current;
4741
+ const completedPreviewDraft = getCompletedDraftPreviewToSuppress({
4742
+ endingTourId,
4743
+ endingPreviewRunId,
4744
+ experienceType
4745
+ });
4718
4746
  isActiveRef.current = false;
4719
4747
  startRequestedRef.current = false;
4720
4748
  releasePlaybackOwnership();
@@ -4724,6 +4752,10 @@ function useTourPlayback({
4724
4752
  runCleanup(pendingManualWaitCleanupRef.current);
4725
4753
  pendingManualWaitCleanupRef.current = null;
4726
4754
  clearPendingManualInputSync();
4755
+ if (completedPreviewDraft) {
4756
+ persistSuppressedDraftPreview(completedPreviewDraft);
4757
+ clearActiveDraftPreview(experienceType);
4758
+ }
4727
4759
  if (!skipRequestedRef.current && userProfile?.userId && tourRef.current) {
4728
4760
  markTourComplete(serverUrl, toursApiBaseRef.current, tourRef.current.id, userProfile.userId, experienceType, websiteId);
4729
4761
  }
@@ -4748,7 +4780,7 @@ function useTourPlayback({
4748
4780
  });
4749
4781
  }
4750
4782
  if (reviewModeRef.current) {
4751
- if (endingTourId) {
4783
+ if (endingTourId && !completedPreviewDraft) {
4752
4784
  persistSuppressedDraftPreview({
4753
4785
  id: endingTourId,
4754
4786
  experienceType
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modelnex/sdk",
3
- "version": "0.5.55",
3
+ "version": "0.5.59",
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",