@modelnex/sdk 0.5.50 → 0.5.52

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.d.mts CHANGED
@@ -477,13 +477,15 @@ interface ModelNexChatBubbleProps {
477
477
  borderRadius?: string;
478
478
  zIndex?: number;
479
479
  };
480
+ /** Whether to auto-start tours configured with auto_start policies based on user state */
481
+ enableAutoDiscovery?: boolean;
480
482
  }
481
483
  /**
482
484
  * Chat interface for natural language commands.
483
485
  * Shows conversation history; on exit, the agent summarizes what it did and suggests next steps.
484
486
  * Use within ModelNexProvider. Omit to use your own UI with useRunCommand.
485
487
  */
486
- declare function ModelNexChatBubble({ placeholder, defaultCommand, className, welcomeMessage, agentName, appName, theme, }: ModelNexChatBubbleProps): React$1.ReactPortal | null;
488
+ declare function ModelNexChatBubble({ placeholder, defaultCommand, className, welcomeMessage, agentName, appName, theme, enableAutoDiscovery, }: ModelNexChatBubbleProps): React$1.ReactPortal | null;
487
489
 
488
490
  interface ModelNexOnboardingPanelProps {
489
491
  appName?: string;
package/dist/index.d.ts CHANGED
@@ -477,13 +477,15 @@ interface ModelNexChatBubbleProps {
477
477
  borderRadius?: string;
478
478
  zIndex?: number;
479
479
  };
480
+ /** Whether to auto-start tours configured with auto_start policies based on user state */
481
+ enableAutoDiscovery?: boolean;
480
482
  }
481
483
  /**
482
484
  * Chat interface for natural language commands.
483
485
  * Shows conversation history; on exit, the agent summarizes what it did and suggests next steps.
484
486
  * Use within ModelNexProvider. Omit to use your own UI with useRunCommand.
485
487
  */
486
- declare function ModelNexChatBubble({ placeholder, defaultCommand, className, welcomeMessage, agentName, appName, theme, }: ModelNexChatBubbleProps): React$1.ReactPortal | null;
488
+ declare function ModelNexChatBubble({ placeholder, defaultCommand, className, welcomeMessage, agentName, appName, theme, enableAutoDiscovery, }: ModelNexChatBubbleProps): React$1.ReactPortal | null;
487
489
 
488
490
  interface ModelNexOnboardingPanelProps {
489
491
  appName?: string;
package/dist/index.js CHANGED
@@ -3881,16 +3881,17 @@ function compactTourForTransport(tour) {
3881
3881
 
3882
3882
  // src/utils/tourSessionPersistence.ts
3883
3883
  var ACTIVE_TOUR_SESSION_STORAGE_KEY = "modelnex-active-tour-session";
3884
- var ACTIVE_TOUR_SESSION_VERSION = 1;
3884
+ var ACTIVE_TOUR_SESSION_VERSION = 2;
3885
3885
  var ACTIVE_TOUR_SESSION_MAX_AGE_MS = 10 * 60 * 1e3;
3886
3886
  function canUseSessionStorage2() {
3887
3887
  return typeof window !== "undefined" && typeof window.sessionStorage !== "undefined";
3888
3888
  }
3889
- function persistActiveTourSession(runId) {
3889
+ function persistActiveTourSession(runId, experienceType) {
3890
3890
  if (!canUseSessionStorage2() || !Number.isFinite(runId)) return;
3891
3891
  const session = {
3892
3892
  version: ACTIVE_TOUR_SESSION_VERSION,
3893
3893
  runId,
3894
+ experienceType,
3894
3895
  savedAt: Date.now()
3895
3896
  };
3896
3897
  try {
@@ -3911,7 +3912,7 @@ function readPersistedActiveTourSession() {
3911
3912
  const raw = window.sessionStorage.getItem(ACTIVE_TOUR_SESSION_STORAGE_KEY);
3912
3913
  if (!raw) return null;
3913
3914
  const parsed = JSON.parse(raw);
3914
- const isValid = parsed && parsed.version === ACTIVE_TOUR_SESSION_VERSION && typeof parsed.runId === "number" && Number.isFinite(parsed.runId) && typeof parsed.savedAt === "number" && Number.isFinite(parsed.savedAt);
3915
+ const isValid = parsed && parsed.version === ACTIVE_TOUR_SESSION_VERSION && typeof parsed.runId === "number" && Number.isFinite(parsed.runId) && typeof parsed.experienceType === "string" && typeof parsed.savedAt === "number" && Number.isFinite(parsed.savedAt);
3915
3916
  if (!isValid) {
3916
3917
  clearPersistedActiveTourSession();
3917
3918
  return null;
@@ -4543,7 +4544,9 @@ function useTourPlayback({
4543
4544
  const pendingTourOptionsRef = (0, import_react12.useRef)(null);
4544
4545
  const showCaptionsRef = (0, import_react12.useRef)(showCaptions);
4545
4546
  const initialPersistedTourSessionRef = (0, import_react12.useRef)(readPersistedActiveTourSession());
4546
- const runIdRef = (0, import_react12.useRef)(initialPersistedTourSessionRef.current?.runId ?? null);
4547
+ const runIdRef = (0, import_react12.useRef)(
4548
+ initialPersistedTourSessionRef.current?.experienceType === experienceType ? initialPersistedTourSessionRef.current.runId : null
4549
+ );
4547
4550
  const turnIdRef = (0, import_react12.useRef)(null);
4548
4551
  const startRequestedRef = (0, import_react12.useRef)(false);
4549
4552
  const serverStateRef = (0, import_react12.useRef)(null);
@@ -4574,7 +4577,8 @@ function useTourPlayback({
4574
4577
  claimedPlaybackOwnerKeyRef.current = null;
4575
4578
  }, []);
4576
4579
  const emitTourInit = (0, import_react12.useCallback)((socket, currentWebsiteId, profile) => {
4577
- const persistedRunId = runIdRef.current ?? readPersistedActiveTourSession()?.runId ?? null;
4580
+ const persistedSession = readPersistedActiveTourSession();
4581
+ const persistedRunId = runIdRef.current ?? (persistedSession?.experienceType === experienceTypeRef.current ? persistedSession.runId : null);
4578
4582
  const payload = {};
4579
4583
  if (currentWebsiteId) {
4580
4584
  payload.websiteId = currentWebsiteId;
@@ -4588,7 +4592,7 @@ function useTourPlayback({
4588
4592
  if (typeof persistedRunId === "number") {
4589
4593
  payload.resumeRunId = persistedRunId;
4590
4594
  }
4591
- if (!payload.resumeRunId && (!payload.websiteId || !payload.userType)) {
4595
+ if (!payload.resumeRunId && (!payload.websiteId || !payload.userType && !payload.userId)) {
4592
4596
  return;
4593
4597
  }
4594
4598
  emitSocketEvent(socket, "tour:init", payload);
@@ -4615,7 +4619,7 @@ function useTourPlayback({
4615
4619
  turnIdRef.current = payload.turnId ?? null;
4616
4620
  }
4617
4621
  if (payload?.isActive && typeof payload?.runId === "number") {
4618
- persistActiveTourSession(payload.runId);
4622
+ persistActiveTourSession(payload.runId, experienceTypeRef.current);
4619
4623
  } else if (payload?.isActive === false) {
4620
4624
  clearPersistedActiveTourSession();
4621
4625
  }
@@ -5250,7 +5254,7 @@ function useTourPlayback({
5250
5254
  if (isActiveRef.current) return;
5251
5255
  runIdRef.current = typeof tourData.runId === "number" ? tourData.runId : runIdRef.current;
5252
5256
  if (typeof runIdRef.current === "number") {
5253
- persistActiveTourSession(runIdRef.current);
5257
+ persistActiveTourSession(runIdRef.current, experienceTypeRef.current);
5254
5258
  }
5255
5259
  const tour = tourData.tourContext ?? tourRef.current;
5256
5260
  const expType = experienceTypeRef.current;
@@ -5951,9 +5955,10 @@ function shouldDiscoverEligibleTours({
5951
5955
  isPreviewDiscoveryInFlight,
5952
5956
  isStartingExperience,
5953
5957
  hasUserProfile,
5954
- hasWebsiteId
5958
+ hasWebsiteId,
5959
+ enableAutoDiscovery
5955
5960
  }) {
5956
- return !disabled && !hasPendingPrompt && !hasPreviewSession && !isPlaybackActive && !isPreviewDiscoveryInFlight && !isStartingExperience && hasUserProfile && hasWebsiteId;
5961
+ return enableAutoDiscovery && !disabled && !hasPendingPrompt && !hasPreviewSession && !isPlaybackActive && !isPreviewDiscoveryInFlight && !isStartingExperience && hasUserProfile && hasWebsiteId;
5957
5962
  }
5958
5963
  function useExperiencePlaybackController({
5959
5964
  serverUrl,
@@ -5969,7 +5974,8 @@ function useExperiencePlaybackController({
5969
5974
  onTourEnd,
5970
5975
  disabled = false,
5971
5976
  showCaptions = true,
5972
- initialExperienceType = "tour"
5977
+ initialExperienceType = "tour",
5978
+ enableAutoDiscovery = true
5973
5979
  }) {
5974
5980
  const locationSignature = typeof window === "undefined" ? "" : getLocationSignature(window.location);
5975
5981
  const [activeExperienceType, setActiveExperienceType] = (0, import_react13.useState)(initialExperienceType);
@@ -6177,8 +6183,10 @@ function useExperiencePlaybackController({
6177
6183
  isPreviewDiscoveryInFlight: previewDiscoveryInFlightRef.current,
6178
6184
  isStartingExperience: startingExperienceType !== null,
6179
6185
  hasUserProfile: Boolean(userProfile),
6180
- hasWebsiteId: Boolean(websiteId)
6186
+ hasWebsiteId: Boolean(websiteId),
6187
+ enableAutoDiscovery
6181
6188
  })) return;
6189
+ if (!userProfile || !websiteId) return;
6182
6190
  let cancelled = false;
6183
6191
  const checkTours = async () => {
6184
6192
  const toursByExperience = await Promise.all(
@@ -10269,7 +10277,8 @@ function ModelNexChatBubble({
10269
10277
  welcomeMessage = "Hi! I can help you navigate and manage your documents. Try asking me to open a document, go to templates, or filter by status.",
10270
10278
  agentName = "ModelNex AI",
10271
10279
  appName = "this app",
10272
- theme
10280
+ theme,
10281
+ enableAutoDiscovery = true
10273
10282
  }) {
10274
10283
  const onCommand = void 0;
10275
10284
  const recordingExperienceType = "tour";
@@ -10342,7 +10351,8 @@ function ModelNexChatBubble({
10342
10351
  },
10343
10352
  showCaptions: !expanded,
10344
10353
  disabled: recordingMode || !hydrated,
10345
- initialExperienceType: recordingExperienceType
10354
+ initialExperienceType: recordingExperienceType,
10355
+ enableAutoDiscovery
10346
10356
  });
10347
10357
  const activePlayback = playbackController.playback;
10348
10358
  const activeExperienceType = playbackController.activeExperienceType;
package/dist/index.mjs CHANGED
@@ -3056,16 +3056,17 @@ function compactTourForTransport(tour) {
3056
3056
 
3057
3057
  // src/utils/tourSessionPersistence.ts
3058
3058
  var ACTIVE_TOUR_SESSION_STORAGE_KEY = "modelnex-active-tour-session";
3059
- var ACTIVE_TOUR_SESSION_VERSION = 1;
3059
+ var ACTIVE_TOUR_SESSION_VERSION = 2;
3060
3060
  var ACTIVE_TOUR_SESSION_MAX_AGE_MS = 10 * 60 * 1e3;
3061
3061
  function canUseSessionStorage2() {
3062
3062
  return typeof window !== "undefined" && typeof window.sessionStorage !== "undefined";
3063
3063
  }
3064
- function persistActiveTourSession(runId) {
3064
+ function persistActiveTourSession(runId, experienceType) {
3065
3065
  if (!canUseSessionStorage2() || !Number.isFinite(runId)) return;
3066
3066
  const session = {
3067
3067
  version: ACTIVE_TOUR_SESSION_VERSION,
3068
3068
  runId,
3069
+ experienceType,
3069
3070
  savedAt: Date.now()
3070
3071
  };
3071
3072
  try {
@@ -3086,7 +3087,7 @@ function readPersistedActiveTourSession() {
3086
3087
  const raw = window.sessionStorage.getItem(ACTIVE_TOUR_SESSION_STORAGE_KEY);
3087
3088
  if (!raw) return null;
3088
3089
  const parsed = JSON.parse(raw);
3089
- const isValid = parsed && parsed.version === ACTIVE_TOUR_SESSION_VERSION && typeof parsed.runId === "number" && Number.isFinite(parsed.runId) && typeof parsed.savedAt === "number" && Number.isFinite(parsed.savedAt);
3090
+ const isValid = parsed && parsed.version === ACTIVE_TOUR_SESSION_VERSION && typeof parsed.runId === "number" && Number.isFinite(parsed.runId) && typeof parsed.experienceType === "string" && typeof parsed.savedAt === "number" && Number.isFinite(parsed.savedAt);
3090
3091
  if (!isValid) {
3091
3092
  clearPersistedActiveTourSession();
3092
3093
  return null;
@@ -3714,7 +3715,9 @@ function useTourPlayback({
3714
3715
  const pendingTourOptionsRef = useRef7(null);
3715
3716
  const showCaptionsRef = useRef7(showCaptions);
3716
3717
  const initialPersistedTourSessionRef = useRef7(readPersistedActiveTourSession());
3717
- const runIdRef = useRef7(initialPersistedTourSessionRef.current?.runId ?? null);
3718
+ const runIdRef = useRef7(
3719
+ initialPersistedTourSessionRef.current?.experienceType === experienceType ? initialPersistedTourSessionRef.current.runId : null
3720
+ );
3718
3721
  const turnIdRef = useRef7(null);
3719
3722
  const startRequestedRef = useRef7(false);
3720
3723
  const serverStateRef = useRef7(null);
@@ -3745,7 +3748,8 @@ function useTourPlayback({
3745
3748
  claimedPlaybackOwnerKeyRef.current = null;
3746
3749
  }, []);
3747
3750
  const emitTourInit = useCallback6((socket, currentWebsiteId, profile) => {
3748
- const persistedRunId = runIdRef.current ?? readPersistedActiveTourSession()?.runId ?? null;
3751
+ const persistedSession = readPersistedActiveTourSession();
3752
+ const persistedRunId = runIdRef.current ?? (persistedSession?.experienceType === experienceTypeRef.current ? persistedSession.runId : null);
3749
3753
  const payload = {};
3750
3754
  if (currentWebsiteId) {
3751
3755
  payload.websiteId = currentWebsiteId;
@@ -3759,7 +3763,7 @@ function useTourPlayback({
3759
3763
  if (typeof persistedRunId === "number") {
3760
3764
  payload.resumeRunId = persistedRunId;
3761
3765
  }
3762
- if (!payload.resumeRunId && (!payload.websiteId || !payload.userType)) {
3766
+ if (!payload.resumeRunId && (!payload.websiteId || !payload.userType && !payload.userId)) {
3763
3767
  return;
3764
3768
  }
3765
3769
  emitSocketEvent(socket, "tour:init", payload);
@@ -3786,7 +3790,7 @@ function useTourPlayback({
3786
3790
  turnIdRef.current = payload.turnId ?? null;
3787
3791
  }
3788
3792
  if (payload?.isActive && typeof payload?.runId === "number") {
3789
- persistActiveTourSession(payload.runId);
3793
+ persistActiveTourSession(payload.runId, experienceTypeRef.current);
3790
3794
  } else if (payload?.isActive === false) {
3791
3795
  clearPersistedActiveTourSession();
3792
3796
  }
@@ -4421,7 +4425,7 @@ function useTourPlayback({
4421
4425
  if (isActiveRef.current) return;
4422
4426
  runIdRef.current = typeof tourData.runId === "number" ? tourData.runId : runIdRef.current;
4423
4427
  if (typeof runIdRef.current === "number") {
4424
- persistActiveTourSession(runIdRef.current);
4428
+ persistActiveTourSession(runIdRef.current, experienceTypeRef.current);
4425
4429
  }
4426
4430
  const tour = tourData.tourContext ?? tourRef.current;
4427
4431
  const expType = experienceTypeRef.current;
@@ -5122,9 +5126,10 @@ function shouldDiscoverEligibleTours({
5122
5126
  isPreviewDiscoveryInFlight,
5123
5127
  isStartingExperience,
5124
5128
  hasUserProfile,
5125
- hasWebsiteId
5129
+ hasWebsiteId,
5130
+ enableAutoDiscovery
5126
5131
  }) {
5127
- return !disabled && !hasPendingPrompt && !hasPreviewSession && !isPlaybackActive && !isPreviewDiscoveryInFlight && !isStartingExperience && hasUserProfile && hasWebsiteId;
5132
+ return enableAutoDiscovery && !disabled && !hasPendingPrompt && !hasPreviewSession && !isPlaybackActive && !isPreviewDiscoveryInFlight && !isStartingExperience && hasUserProfile && hasWebsiteId;
5128
5133
  }
5129
5134
  function useExperiencePlaybackController({
5130
5135
  serverUrl,
@@ -5140,7 +5145,8 @@ function useExperiencePlaybackController({
5140
5145
  onTourEnd,
5141
5146
  disabled = false,
5142
5147
  showCaptions = true,
5143
- initialExperienceType = "tour"
5148
+ initialExperienceType = "tour",
5149
+ enableAutoDiscovery = true
5144
5150
  }) {
5145
5151
  const locationSignature = typeof window === "undefined" ? "" : getLocationSignature(window.location);
5146
5152
  const [activeExperienceType, setActiveExperienceType] = useState7(initialExperienceType);
@@ -5348,8 +5354,10 @@ function useExperiencePlaybackController({
5348
5354
  isPreviewDiscoveryInFlight: previewDiscoveryInFlightRef.current,
5349
5355
  isStartingExperience: startingExperienceType !== null,
5350
5356
  hasUserProfile: Boolean(userProfile),
5351
- hasWebsiteId: Boolean(websiteId)
5357
+ hasWebsiteId: Boolean(websiteId),
5358
+ enableAutoDiscovery
5352
5359
  })) return;
5360
+ if (!userProfile || !websiteId) return;
5353
5361
  let cancelled = false;
5354
5362
  const checkTours = async () => {
5355
5363
  const toursByExperience = await Promise.all(
@@ -9438,7 +9446,8 @@ function ModelNexChatBubble({
9438
9446
  welcomeMessage = "Hi! I can help you navigate and manage your documents. Try asking me to open a document, go to templates, or filter by status.",
9439
9447
  agentName = "ModelNex AI",
9440
9448
  appName = "this app",
9441
- theme
9449
+ theme,
9450
+ enableAutoDiscovery = true
9442
9451
  }) {
9443
9452
  const onCommand = void 0;
9444
9453
  const recordingExperienceType = "tour";
@@ -9511,7 +9520,8 @@ function ModelNexChatBubble({
9511
9520
  },
9512
9521
  showCaptions: !expanded,
9513
9522
  disabled: recordingMode || !hydrated,
9514
- initialExperienceType: recordingExperienceType
9523
+ initialExperienceType: recordingExperienceType,
9524
+ enableAutoDiscovery
9515
9525
  });
9516
9526
  const activePlayback = playbackController.playback;
9517
9527
  const activeExperienceType = playbackController.activeExperienceType;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modelnex/sdk",
3
- "version": "0.5.50",
3
+ "version": "0.5.52",
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",