@modelnex/sdk 0.5.31 → 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;
@@ -11794,7 +11820,8 @@ var ModelNexProvider = ({
11794
11820
  const [socketId, setSocketId] = (0, import_react21.useState)(null);
11795
11821
  const [actions, setActions] = (0, import_react21.useState)(/* @__PURE__ */ new Map());
11796
11822
  const [validatedBrowserDevMode, setValidatedBrowserDevMode] = (0, import_react21.useState)(false);
11797
- const resolvedDevModeKey = (0, import_react21.useMemo)(() => resolveInjectedDevModeKey(), []);
11823
+ const [resolvedDevModeKey, setResolvedDevModeKey] = (0, import_react21.useState)(() => resolveInjectedDevModeKey());
11824
+ (0, import_react21.useEffect)(() => observeInjectedDevModeKey(setResolvedDevModeKey), []);
11798
11825
  (0, import_react21.useEffect)(() => {
11799
11826
  let cancelled = false;
11800
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;
@@ -11584,7 +11610,8 @@ var ModelNexProvider = ({
11584
11610
  const [socketId, setSocketId] = useState15(null);
11585
11611
  const [actions, setActions] = useState15(/* @__PURE__ */ new Map());
11586
11612
  const [validatedBrowserDevMode, setValidatedBrowserDevMode] = useState15(false);
11587
- const resolvedDevModeKey = useMemo5(() => resolveInjectedDevModeKey(), []);
11613
+ const [resolvedDevModeKey, setResolvedDevModeKey] = useState15(() => resolveInjectedDevModeKey());
11614
+ useEffect19(() => observeInjectedDevModeKey(setResolvedDevModeKey), []);
11588
11615
  useEffect19(() => {
11589
11616
  let cancelled = false;
11590
11617
  if (!websiteId || !resolvedDevModeKey) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modelnex/sdk",
3
- "version": "0.5.31",
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
- };