@modelnex/sdk 0.5.30 → 0.5.32

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
@@ -2766,6 +2766,32 @@ function normalizeDevModeKey(value) {
2766
2766
  const normalized = value.trim();
2767
2767
  return normalized || void 0;
2768
2768
  }
2769
+ function observeInjectedDevModeKey(listener, options) {
2770
+ if (typeof window === "undefined") return () => {
2771
+ };
2772
+ let currentKey = resolveInjectedDevModeKey();
2773
+ const pollIntervalMs = options?.pollIntervalMs ?? 1e3;
2774
+ const syncInjectedDevModeKey = () => {
2775
+ const nextKey = resolveInjectedDevModeKey();
2776
+ if (nextKey === currentKey) return;
2777
+ currentKey = nextKey;
2778
+ listener(nextKey);
2779
+ };
2780
+ const intervalId = window.setInterval(syncInjectedDevModeKey, pollIntervalMs);
2781
+ window.addEventListener("focus", syncInjectedDevModeKey);
2782
+ window.addEventListener("pageshow", syncInjectedDevModeKey);
2783
+ if (typeof document !== "undefined") {
2784
+ document.addEventListener("visibilitychange", syncInjectedDevModeKey);
2785
+ }
2786
+ return () => {
2787
+ window.clearInterval(intervalId);
2788
+ window.removeEventListener("focus", syncInjectedDevModeKey);
2789
+ window.removeEventListener("pageshow", syncInjectedDevModeKey);
2790
+ if (typeof document !== "undefined") {
2791
+ document.removeEventListener("visibilitychange", syncInjectedDevModeKey);
2792
+ }
2793
+ };
2794
+ }
2769
2795
  function resolveInjectedDevModeKey() {
2770
2796
  if (typeof window === "undefined") return void 0;
2771
2797
  const browserWindow = window;
@@ -8878,9 +8904,40 @@ var TOUR_THEME = {
8878
8904
  cardBorder: "var(--modelnex-tour-card-border, rgba(79, 70, 229, 0.12))",
8879
8905
  actionBg: "var(--modelnex-tour-action-bg, #1e1b4b)"
8880
8906
  };
8907
+ var DOCKED_DESKTOP_PANEL_HEIGHT_RATIO = 0.7;
8908
+ var UNDOCKED_DESKTOP_PANEL_HEIGHT_RATIO = 0.4;
8881
8909
  function shouldIgnoreTourGestureStart(target) {
8882
8910
  return target instanceof HTMLElement && Boolean(target.closest('[data-modelnex-review-toggle="true"]'));
8883
8911
  }
8912
+ function getViewportHeight() {
8913
+ if (typeof window === "undefined") return 0;
8914
+ const layoutViewportHeight = window.innerHeight || document.documentElement?.clientHeight || 0;
8915
+ const visualViewportHeight = window.visualViewport?.height;
8916
+ if (typeof visualViewportHeight === "number" && Number.isFinite(visualViewportHeight) && visualViewportHeight > 0) {
8917
+ return Math.round(Math.min(layoutViewportHeight || visualViewportHeight, visualViewportHeight));
8918
+ }
8919
+ return layoutViewportHeight;
8920
+ }
8921
+ function useViewportHeight() {
8922
+ const [viewportHeight, setViewportHeight] = (0, import_react18.useState)(() => getViewportHeight());
8923
+ (0, import_react18.useEffect)(() => {
8924
+ if (typeof window === "undefined") return;
8925
+ const updateViewportHeight = () => {
8926
+ setViewportHeight(getViewportHeight());
8927
+ };
8928
+ updateViewportHeight();
8929
+ const visualViewport = window.visualViewport;
8930
+ window.addEventListener("resize", updateViewportHeight, { passive: true });
8931
+ visualViewport?.addEventListener("resize", updateViewportHeight);
8932
+ visualViewport?.addEventListener("scroll", updateViewportHeight);
8933
+ return () => {
8934
+ window.removeEventListener("resize", updateViewportHeight);
8935
+ visualViewport?.removeEventListener("resize", updateViewportHeight);
8936
+ visualViewport?.removeEventListener("scroll", updateViewportHeight);
8937
+ };
8938
+ }, []);
8939
+ return viewportHeight;
8940
+ }
8884
8941
  function useMediaQuery(query) {
8885
8942
  const [matches, setMatches] = (0, import_react18.useState)(false);
8886
8943
  (0, import_react18.useEffect)(() => {
@@ -9776,6 +9833,7 @@ function ModelNexChatBubble({
9776
9833
  e.stopPropagation();
9777
9834
  };
9778
9835
  const isMobile = useMediaQuery("(max-width: 640px)");
9836
+ const viewportHeight = useViewportHeight();
9779
9837
  const themeStyles = (0, import_react18.useMemo)(() => {
9780
9838
  if (!theme) return null;
9781
9839
  const styles = {};
@@ -9805,13 +9863,13 @@ function ModelNexChatBubble({
9805
9863
  fontFamily: "var(--modelnex-font)",
9806
9864
  ...themeStyles
9807
9865
  };
9808
- const desktopPanelHeight = docked ? "min(calc(100vh - 48px), calc(var(--modelnex-panel-max-height, 600px) + 180px))" : "var(--modelnex-panel-max-height, 600px)";
9809
- const desktopPanelMaxHeight = docked ? "calc(100vh - 48px)" : "calc(100vh - 120px)";
9866
+ const desktopPanelHeightRatio = docked ? DOCKED_DESKTOP_PANEL_HEIGHT_RATIO : UNDOCKED_DESKTOP_PANEL_HEIGHT_RATIO;
9867
+ const desktopPanelHeight = viewportHeight > 0 ? `${Math.round(viewportHeight * desktopPanelHeightRatio)}px` : docked ? "70vh" : "40vh";
9810
9868
  const panelStyle = {
9811
9869
  width: isMobile ? "100%" : "var(--modelnex-panel-width, 380px)",
9812
9870
  maxWidth: "calc(100vw - 32px)",
9813
9871
  height: isMobile ? "100%" : desktopPanelHeight,
9814
- maxHeight: isMobile ? "100%" : desktopPanelMaxHeight,
9872
+ maxHeight: isMobile ? "100%" : desktopPanelHeight,
9815
9873
  borderRadius: isMobile ? "0" : "var(--modelnex-radius-panel, 20px)",
9816
9874
  border: isMobile ? "none" : "1px solid var(--modelnex-border, #e4e4e7)",
9817
9875
  background: "var(--modelnex-bg, #ffffff)",
@@ -11762,7 +11820,8 @@ var ModelNexProvider = ({
11762
11820
  const [socketId, setSocketId] = (0, import_react21.useState)(null);
11763
11821
  const [actions, setActions] = (0, import_react21.useState)(/* @__PURE__ */ new Map());
11764
11822
  const [validatedBrowserDevMode, setValidatedBrowserDevMode] = (0, import_react21.useState)(false);
11765
- const resolvedDevModeKey = (0, import_react21.useMemo)(() => resolveInjectedDevModeKey(), []);
11823
+ const [resolvedDevModeKey, setResolvedDevModeKey] = (0, import_react21.useState)(() => resolveInjectedDevModeKey());
11824
+ (0, import_react21.useEffect)(() => observeInjectedDevModeKey(setResolvedDevModeKey), []);
11766
11825
  (0, import_react21.useEffect)(() => {
11767
11826
  let cancelled = false;
11768
11827
  if (!websiteId || !resolvedDevModeKey) {
package/dist/index.mjs CHANGED
@@ -2557,6 +2557,32 @@ function normalizeDevModeKey(value) {
2557
2557
  const normalized = value.trim();
2558
2558
  return normalized || void 0;
2559
2559
  }
2560
+ function observeInjectedDevModeKey(listener, options) {
2561
+ if (typeof window === "undefined") return () => {
2562
+ };
2563
+ let currentKey = resolveInjectedDevModeKey();
2564
+ const pollIntervalMs = options?.pollIntervalMs ?? 1e3;
2565
+ const syncInjectedDevModeKey = () => {
2566
+ const nextKey = resolveInjectedDevModeKey();
2567
+ if (nextKey === currentKey) return;
2568
+ currentKey = nextKey;
2569
+ listener(nextKey);
2570
+ };
2571
+ const intervalId = window.setInterval(syncInjectedDevModeKey, pollIntervalMs);
2572
+ window.addEventListener("focus", syncInjectedDevModeKey);
2573
+ window.addEventListener("pageshow", syncInjectedDevModeKey);
2574
+ if (typeof document !== "undefined") {
2575
+ document.addEventListener("visibilitychange", syncInjectedDevModeKey);
2576
+ }
2577
+ return () => {
2578
+ window.clearInterval(intervalId);
2579
+ window.removeEventListener("focus", syncInjectedDevModeKey);
2580
+ window.removeEventListener("pageshow", syncInjectedDevModeKey);
2581
+ if (typeof document !== "undefined") {
2582
+ document.removeEventListener("visibilitychange", syncInjectedDevModeKey);
2583
+ }
2584
+ };
2585
+ }
2560
2586
  function resolveInjectedDevModeKey() {
2561
2587
  if (typeof window === "undefined") return void 0;
2562
2588
  const browserWindow = window;
@@ -8668,9 +8694,40 @@ var TOUR_THEME = {
8668
8694
  cardBorder: "var(--modelnex-tour-card-border, rgba(79, 70, 229, 0.12))",
8669
8695
  actionBg: "var(--modelnex-tour-action-bg, #1e1b4b)"
8670
8696
  };
8697
+ var DOCKED_DESKTOP_PANEL_HEIGHT_RATIO = 0.7;
8698
+ var UNDOCKED_DESKTOP_PANEL_HEIGHT_RATIO = 0.4;
8671
8699
  function shouldIgnoreTourGestureStart(target) {
8672
8700
  return target instanceof HTMLElement && Boolean(target.closest('[data-modelnex-review-toggle="true"]'));
8673
8701
  }
8702
+ function getViewportHeight() {
8703
+ if (typeof window === "undefined") return 0;
8704
+ const layoutViewportHeight = window.innerHeight || document.documentElement?.clientHeight || 0;
8705
+ const visualViewportHeight = window.visualViewport?.height;
8706
+ if (typeof visualViewportHeight === "number" && Number.isFinite(visualViewportHeight) && visualViewportHeight > 0) {
8707
+ return Math.round(Math.min(layoutViewportHeight || visualViewportHeight, visualViewportHeight));
8708
+ }
8709
+ return layoutViewportHeight;
8710
+ }
8711
+ function useViewportHeight() {
8712
+ const [viewportHeight, setViewportHeight] = useState13(() => getViewportHeight());
8713
+ useEffect17(() => {
8714
+ if (typeof window === "undefined") return;
8715
+ const updateViewportHeight = () => {
8716
+ setViewportHeight(getViewportHeight());
8717
+ };
8718
+ updateViewportHeight();
8719
+ const visualViewport = window.visualViewport;
8720
+ window.addEventListener("resize", updateViewportHeight, { passive: true });
8721
+ visualViewport?.addEventListener("resize", updateViewportHeight);
8722
+ visualViewport?.addEventListener("scroll", updateViewportHeight);
8723
+ return () => {
8724
+ window.removeEventListener("resize", updateViewportHeight);
8725
+ visualViewport?.removeEventListener("resize", updateViewportHeight);
8726
+ visualViewport?.removeEventListener("scroll", updateViewportHeight);
8727
+ };
8728
+ }, []);
8729
+ return viewportHeight;
8730
+ }
8674
8731
  function useMediaQuery(query) {
8675
8732
  const [matches, setMatches] = useState13(false);
8676
8733
  useEffect17(() => {
@@ -9566,6 +9623,7 @@ function ModelNexChatBubble({
9566
9623
  e.stopPropagation();
9567
9624
  };
9568
9625
  const isMobile = useMediaQuery("(max-width: 640px)");
9626
+ const viewportHeight = useViewportHeight();
9569
9627
  const themeStyles = useMemo3(() => {
9570
9628
  if (!theme) return null;
9571
9629
  const styles = {};
@@ -9595,13 +9653,13 @@ function ModelNexChatBubble({
9595
9653
  fontFamily: "var(--modelnex-font)",
9596
9654
  ...themeStyles
9597
9655
  };
9598
- const desktopPanelHeight = docked ? "min(calc(100vh - 48px), calc(var(--modelnex-panel-max-height, 600px) + 180px))" : "var(--modelnex-panel-max-height, 600px)";
9599
- const desktopPanelMaxHeight = docked ? "calc(100vh - 48px)" : "calc(100vh - 120px)";
9656
+ const desktopPanelHeightRatio = docked ? DOCKED_DESKTOP_PANEL_HEIGHT_RATIO : UNDOCKED_DESKTOP_PANEL_HEIGHT_RATIO;
9657
+ const desktopPanelHeight = viewportHeight > 0 ? `${Math.round(viewportHeight * desktopPanelHeightRatio)}px` : docked ? "70vh" : "40vh";
9600
9658
  const panelStyle = {
9601
9659
  width: isMobile ? "100%" : "var(--modelnex-panel-width, 380px)",
9602
9660
  maxWidth: "calc(100vw - 32px)",
9603
9661
  height: isMobile ? "100%" : desktopPanelHeight,
9604
- maxHeight: isMobile ? "100%" : desktopPanelMaxHeight,
9662
+ maxHeight: isMobile ? "100%" : desktopPanelHeight,
9605
9663
  borderRadius: isMobile ? "0" : "var(--modelnex-radius-panel, 20px)",
9606
9664
  border: isMobile ? "none" : "1px solid var(--modelnex-border, #e4e4e7)",
9607
9665
  background: "var(--modelnex-bg, #ffffff)",
@@ -11552,7 +11610,8 @@ var ModelNexProvider = ({
11552
11610
  const [socketId, setSocketId] = useState15(null);
11553
11611
  const [actions, setActions] = useState15(/* @__PURE__ */ new Map());
11554
11612
  const [validatedBrowserDevMode, setValidatedBrowserDevMode] = useState15(false);
11555
- const resolvedDevModeKey = useMemo5(() => resolveInjectedDevModeKey(), []);
11613
+ const [resolvedDevModeKey, setResolvedDevModeKey] = useState15(() => resolveInjectedDevModeKey());
11614
+ useEffect19(() => observeInjectedDevModeKey(setResolvedDevModeKey), []);
11556
11615
  useEffect19(() => {
11557
11616
  let cancelled = false;
11558
11617
  if (!websiteId || !resolvedDevModeKey) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modelnex/sdk",
3
- "version": "0.5.30",
3
+ "version": "0.5.32",
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",
@@ -20,15 +20,6 @@
20
20
  "dist",
21
21
  "README.md"
22
22
  ],
23
- "scripts": {
24
- "prepublishOnly": "npm run build",
25
- "build": "npm exec -- tsup src/index.ts --format cjs,esm --dts",
26
- "dev": "npm exec -- tsup src/index.ts --format cjs,esm --watch --dts",
27
- "lint": "eslint src/",
28
- "test": "npm run build && node --test tests/*.test.js",
29
- "test:ci": "npm run test && npm run test:unit",
30
- "test:unit": "node --import tsx --test tests/*.test.ts"
31
- },
32
23
  "peerDependencies": {
33
24
  "react": ">=17.0.0",
34
25
  "react-dom": ">=17.0.0",
@@ -67,5 +58,13 @@
67
58
  "bugs": {
68
59
  "url": "https://github.com/sharunaraksha/modelnex-sdk/issues"
69
60
  },
70
- "homepage": "https://github.com/sharunaraksha/modelnex-sdk#readme"
71
- }
61
+ "homepage": "https://github.com/sharunaraksha/modelnex-sdk#readme",
62
+ "scripts": {
63
+ "build": "npm exec -- tsup src/index.ts --format cjs,esm --dts",
64
+ "dev": "npm exec -- tsup src/index.ts --format cjs,esm --watch --dts",
65
+ "lint": "eslint src/",
66
+ "test": "npm run build && node --test tests/*.test.js",
67
+ "test:ci": "npm run test && npm run test:unit",
68
+ "test:unit": "node --import tsx --test tests/*.test.ts"
69
+ }
70
+ }
@@ -1,55 +0,0 @@
1
- // src/utils/dom-sync.ts
2
- function waitForDomSettle(options = {}) {
3
- const { timeoutMs = 5e3, debounceMs = 400, minWaitMs = 100 } = options;
4
- return new Promise((resolve) => {
5
- let debounceTimer = null;
6
- let resolved = false;
7
- const maxTimer = setTimeout(() => {
8
- if (!resolved) {
9
- resolved = true;
10
- cleanup();
11
- console.log("[DOM Sync] Forced resolution by max timeout");
12
- resolve();
13
- }
14
- }, Math.max(timeoutMs, minWaitMs));
15
- const finish = () => {
16
- if (!resolved) {
17
- resolved = true;
18
- cleanup();
19
- resolve();
20
- }
21
- };
22
- const observer = new MutationObserver((mutations) => {
23
- const hasSignificantMutations = mutations.some((m) => {
24
- if (m.target instanceof HTMLElement) {
25
- if (m.target.hasAttribute("data-modelnex-tour-highlight")) return false;
26
- if (m.target.hasAttribute("data-modelnex-caption")) return false;
27
- if (m.target.closest("#modelnex-studio-root")) return false;
28
- if (m.target.closest("#modelnex-active-agent-root")) return false;
29
- }
30
- return true;
31
- });
32
- if (!hasSignificantMutations) return;
33
- if (debounceTimer) clearTimeout(debounceTimer);
34
- debounceTimer = setTimeout(finish, debounceMs);
35
- });
36
- const cleanup = () => {
37
- observer.disconnect();
38
- if (debounceTimer) clearTimeout(debounceTimer);
39
- clearTimeout(maxTimer);
40
- };
41
- setTimeout(() => {
42
- if (resolved) return;
43
- observer.observe(document.body, {
44
- childList: true,
45
- subtree: true,
46
- attributes: true,
47
- characterData: true
48
- });
49
- debounceTimer = setTimeout(finish, debounceMs);
50
- }, minWaitMs);
51
- });
52
- }
53
- export {
54
- waitForDomSettle
55
- };