@modelnex/sdk 0.5.8 → 0.5.10

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
@@ -827,6 +827,10 @@ interface ModelNexProviderProps {
827
827
  * userId — used for per-user tour completion state
828
828
  */
829
829
  userProfile?: UserProfile;
830
+ /**
831
+ * Same-origin base for tour API (avoids CORS for ?modelnex_test_tour=)
832
+ */
833
+ toursApiBase?: string;
830
834
  /**
831
835
  * Enable SDK dev tools unconditionally (tour recording, studio mode)
832
836
  */
package/dist/index.d.ts CHANGED
@@ -827,6 +827,10 @@ interface ModelNexProviderProps {
827
827
  * userId — used for per-user tour completion state
828
828
  */
829
829
  userProfile?: UserProfile;
830
+ /**
831
+ * Same-origin base for tour API (avoids CORS for ?modelnex_test_tour=)
832
+ */
833
+ toursApiBase?: string;
830
834
  /**
831
835
  * Enable SDK dev tools unconditionally (tour recording, studio mode)
832
836
  */
package/dist/index.js CHANGED
@@ -222,6 +222,18 @@ var ModelNexContext = (0, import_react.createContext)(null);
222
222
  var import_react3 = require("react");
223
223
  var import_socket = require("socket.io-client");
224
224
 
225
+ // src/utils/socket-io-transports.ts
226
+ function resolveSocketIoTransports(serverUrl, order) {
227
+ try {
228
+ const host = new URL(serverUrl).hostname.toLowerCase();
229
+ if (host.endsWith("awsapprunner.com")) {
230
+ return ["polling"];
231
+ }
232
+ } catch {
233
+ }
234
+ return order === "websocket-first" ? ["websocket", "polling"] : ["polling", "websocket"];
235
+ }
236
+
225
237
  // src/auto-extract.ts
226
238
  var import_react2 = require("react");
227
239
  function simpleHash(str) {
@@ -839,7 +851,10 @@ function useModelNexSocket({
839
851
  onSocketId?.(null);
840
852
  return;
841
853
  }
842
- const socket = (0, import_socket.io)(serverUrl);
854
+ const socket = (0, import_socket.io)(serverUrl, {
855
+ path: "/socket.io",
856
+ transports: resolveSocketIoTransports(serverUrl, "polling-first")
857
+ });
843
858
  socketRef.current = socket;
844
859
  const buildSyncPayload = () => ({
845
860
  actions: serializeActions(actionsRef.current),
@@ -3180,7 +3195,7 @@ function useTourPlayback({
3180
3195
  const socket = io2(serverUrl, {
3181
3196
  path: "/socket.io",
3182
3197
  // standard
3183
- transports: ["websocket", "polling"]
3198
+ transports: resolveSocketIoTransports(serverUrl, "websocket-first")
3184
3199
  });
3185
3200
  socketRef.current = socket;
3186
3201
  socket.on("connect", () => {
@@ -5435,7 +5450,7 @@ function useVoice(serverUrl) {
5435
5450
  mediaRecorderRef.current = recorder;
5436
5451
  const socket = io2(serverUrl, {
5437
5452
  path: "/socket.io",
5438
- transports: ["websocket", "polling"]
5453
+ transports: resolveSocketIoTransports(serverUrl, "websocket-first")
5439
5454
  });
5440
5455
  sttSocketRef.current = socket;
5441
5456
  recorder.ondataavailable = (e) => {
@@ -8176,6 +8191,11 @@ var CloseIcon = () => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("svg", { wid
8176
8191
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
8177
8192
  ] });
8178
8193
  var MinimizeIcon = () => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("path", { d: "M8 18h8" }) });
8194
+ var TrashIcon = () => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
8195
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("path", { d: "M3 6h18" }),
8196
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("path", { d: "M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6" }),
8197
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("path", { d: "M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2" })
8198
+ ] });
8179
8199
  var StopIcon = () => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("rect", { x: "6", y: "6", width: "12", height: "12", rx: "2" }) });
8180
8200
  var ChevronDown = ({ open }) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", style: { transform: open ? "rotate(180deg)" : "none", transition: "transform 0.2s" }, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("path", { d: "m6 9 6 6 6-6" }) });
8181
8201
  function AgentTraces({ debug, command, defaultExpanded = true }) {
@@ -8237,7 +8257,7 @@ function AgentTraces({ debug, command, defaultExpanded = true }) {
8237
8257
  !hasTraceContent ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: { marginBottom: "12px", padding: "8px", background: "#fef3c7", borderRadius: "4px", borderLeft: "3px solid #f59e0b" }, children: [
8238
8258
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { style: { fontWeight: 600, color: "#92400e", marginBottom: "4px" }, children: "No trace data" }),
8239
8259
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { style: { fontSize: "10px", color: "#71717a", marginBottom: "6px" }, children: "The server may not have OPENROUTER_API_KEY set, or the request failed before the agent ran." }),
8240
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("pre", { style: { margin: 0, padding: "8px", background: "#fff", borderRadius: "4px", fontSize: "10px", overflow: "auto", maxHeight: "120px" }, children: JSON.stringify(debug, null, 2) })
8260
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("pre", { style: { margin: 0, padding: "8px", background: "#fff", borderRadius: "4px", fontSize: "10px", overflow: "auto", maxHeight: "120px", color: "#27272a" }, children: JSON.stringify(debug, null, 2) })
8241
8261
  ] }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
8242
8262
  debug.llmInput && traces.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: { marginBottom: "12px" }, children: [
8243
8263
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { style: { fontWeight: 600, color: "#3f3f46", marginBottom: "4px" }, children: "Input \u2192 agent" }),
@@ -8284,7 +8304,7 @@ function AgentTraces({ debug, command, defaultExpanded = true }) {
8284
8304
  isStepExpanded && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
8285
8305
  t.reasoning && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: { marginBottom: "6px" }, children: [
8286
8306
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { style: { color: "#71717a", marginBottom: "2px" }, children: "Reasoning" }),
8287
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("pre", { style: { margin: 0, padding: "6px", background: "#fef3c7", borderRadius: "4px", whiteSpace: "pre-wrap", wordBreak: "break-word", maxHeight: "100px", overflow: "auto", borderLeft: "3px solid #f59e0b" }, children: t.reasoning })
8307
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("pre", { style: { margin: 0, padding: "6px", background: "#fef3c7", borderRadius: "4px", whiteSpace: "pre-wrap", wordBreak: "break-word", maxHeight: "100px", overflow: "auto", borderLeft: "3px solid #f59e0b", color: "#451a03" }, children: t.reasoning })
8288
8308
  ] }),
8289
8309
  t.llmInput && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
8290
8310
  /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: { marginBottom: "6px" }, children: [
@@ -9144,6 +9164,15 @@ function ModelNexChatBubble({
9144
9164
  children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(BookOpenIcon, {})
9145
9165
  }
9146
9166
  ) }) }),
9167
+ messages.length > 0 && !(tourPlayback.isActive || onboardingPlayback.isActive) && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Tooltip, { title: "Clear chat", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
9168
+ "button",
9169
+ {
9170
+ onClick: clearChat,
9171
+ style: { padding: "8px", borderRadius: "10px", border: "none", background: "transparent", cursor: "pointer", color: "#71717a" },
9172
+ "aria-label": "Clear chat",
9173
+ children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(TrashIcon, {})
9174
+ }
9175
+ ) }),
9147
9176
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Tooltip, { title: "Minimize", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
9148
9177
  "button",
9149
9178
  {
@@ -10879,12 +10908,12 @@ var ModelNexProvider = ({
10879
10908
  children,
10880
10909
  websiteId,
10881
10910
  userProfile,
10911
+ toursApiBase,
10882
10912
  devMode
10883
10913
  }) => {
10884
10914
  const serverUrl = DEFAULT_SERVER_URL2;
10885
10915
  const commandUrl = void 0;
10886
10916
  const disableSocket = false;
10887
- const toursApiBase = void 0;
10888
10917
  const renderedChildren = children;
10889
10918
  const [activeAgentActions, setActiveAgentActions] = (0, import_react21.useState)(/* @__PURE__ */ new Set());
10890
10919
  const [stagingFields, setStagingFields] = (0, import_react21.useState)(/* @__PURE__ */ new Set());
@@ -10975,12 +11004,13 @@ var ModelNexProvider = ({
10975
11004
  setChatMessages,
10976
11005
  websiteId,
10977
11006
  userProfile,
11007
+ toursApiBase,
10978
11008
  voiceMuted,
10979
11009
  setVoiceMuted,
10980
11010
  socketId,
10981
11011
  devMode
10982
11012
  }),
10983
- [serverUrl, commandUrl, registerAction, unregisterAction, activeAgentActions, stagingFields, highlightActions, studioMode, recordingMode, extractedElements, tagStore, chatMessages, websiteId, userProfile, voiceMuted, socketId, devMode]
11013
+ [serverUrl, commandUrl, registerAction, unregisterAction, activeAgentActions, stagingFields, highlightActions, studioMode, recordingMode, extractedElements, tagStore, chatMessages, websiteId, userProfile, toursApiBase, voiceMuted, socketId, devMode]
10984
11014
  );
10985
11015
  return import_react21.default.createElement(
10986
11016
  ModelNexContext.Provider,
package/dist/index.mjs CHANGED
@@ -13,6 +13,18 @@ var ModelNexContext = createContext(null);
13
13
  import { useEffect as useEffect3, useRef as useRef3 } from "react";
14
14
  import { io } from "socket.io-client";
15
15
 
16
+ // src/utils/socket-io-transports.ts
17
+ function resolveSocketIoTransports(serverUrl, order) {
18
+ try {
19
+ const host = new URL(serverUrl).hostname.toLowerCase();
20
+ if (host.endsWith("awsapprunner.com")) {
21
+ return ["polling"];
22
+ }
23
+ } catch {
24
+ }
25
+ return order === "websocket-first" ? ["websocket", "polling"] : ["polling", "websocket"];
26
+ }
27
+
16
28
  // src/auto-extract.ts
17
29
  import { useState, useEffect as useEffect2, useRef as useRef2, useCallback as useCallback2 } from "react";
18
30
  function simpleHash(str) {
@@ -630,7 +642,10 @@ function useModelNexSocket({
630
642
  onSocketId?.(null);
631
643
  return;
632
644
  }
633
- const socket = io(serverUrl);
645
+ const socket = io(serverUrl, {
646
+ path: "/socket.io",
647
+ transports: resolveSocketIoTransports(serverUrl, "polling-first")
648
+ });
634
649
  socketRef.current = socket;
635
650
  const buildSyncPayload = () => ({
636
651
  actions: serializeActions(actionsRef.current),
@@ -2971,7 +2986,7 @@ function useTourPlayback({
2971
2986
  const socket = io2(serverUrl, {
2972
2987
  path: "/socket.io",
2973
2988
  // standard
2974
- transports: ["websocket", "polling"]
2989
+ transports: resolveSocketIoTransports(serverUrl, "websocket-first")
2975
2990
  });
2976
2991
  socketRef.current = socket;
2977
2992
  socket.on("connect", () => {
@@ -5226,7 +5241,7 @@ function useVoice(serverUrl) {
5226
5241
  mediaRecorderRef.current = recorder;
5227
5242
  const socket = io2(serverUrl, {
5228
5243
  path: "/socket.io",
5229
- transports: ["websocket", "polling"]
5244
+ transports: resolveSocketIoTransports(serverUrl, "websocket-first")
5230
5245
  });
5231
5246
  sttSocketRef.current = socket;
5232
5247
  recorder.ondataavailable = (e) => {
@@ -7966,6 +7981,11 @@ var CloseIcon = () => /* @__PURE__ */ jsxs3("svg", { width: "var(--modelnex-bubb
7966
7981
  /* @__PURE__ */ jsx4("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
7967
7982
  ] });
7968
7983
  var MinimizeIcon = () => /* @__PURE__ */ jsx4("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ jsx4("path", { d: "M8 18h8" }) });
7984
+ var TrashIcon = () => /* @__PURE__ */ jsxs3("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
7985
+ /* @__PURE__ */ jsx4("path", { d: "M3 6h18" }),
7986
+ /* @__PURE__ */ jsx4("path", { d: "M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6" }),
7987
+ /* @__PURE__ */ jsx4("path", { d: "M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2" })
7988
+ ] });
7969
7989
  var StopIcon = () => /* @__PURE__ */ jsx4("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ jsx4("rect", { x: "6", y: "6", width: "12", height: "12", rx: "2" }) });
7970
7990
  var ChevronDown = ({ open }) => /* @__PURE__ */ jsx4("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", style: { transform: open ? "rotate(180deg)" : "none", transition: "transform 0.2s" }, children: /* @__PURE__ */ jsx4("path", { d: "m6 9 6 6 6-6" }) });
7971
7991
  function AgentTraces({ debug, command, defaultExpanded = true }) {
@@ -8027,7 +8047,7 @@ function AgentTraces({ debug, command, defaultExpanded = true }) {
8027
8047
  !hasTraceContent ? /* @__PURE__ */ jsxs3("div", { style: { marginBottom: "12px", padding: "8px", background: "#fef3c7", borderRadius: "4px", borderLeft: "3px solid #f59e0b" }, children: [
8028
8048
  /* @__PURE__ */ jsx4("div", { style: { fontWeight: 600, color: "#92400e", marginBottom: "4px" }, children: "No trace data" }),
8029
8049
  /* @__PURE__ */ jsx4("div", { style: { fontSize: "10px", color: "#71717a", marginBottom: "6px" }, children: "The server may not have OPENROUTER_API_KEY set, or the request failed before the agent ran." }),
8030
- /* @__PURE__ */ jsx4("pre", { style: { margin: 0, padding: "8px", background: "#fff", borderRadius: "4px", fontSize: "10px", overflow: "auto", maxHeight: "120px" }, children: JSON.stringify(debug, null, 2) })
8050
+ /* @__PURE__ */ jsx4("pre", { style: { margin: 0, padding: "8px", background: "#fff", borderRadius: "4px", fontSize: "10px", overflow: "auto", maxHeight: "120px", color: "#27272a" }, children: JSON.stringify(debug, null, 2) })
8031
8051
  ] }) : /* @__PURE__ */ jsxs3(Fragment2, { children: [
8032
8052
  debug.llmInput && traces.length === 0 && /* @__PURE__ */ jsxs3("div", { style: { marginBottom: "12px" }, children: [
8033
8053
  /* @__PURE__ */ jsx4("div", { style: { fontWeight: 600, color: "#3f3f46", marginBottom: "4px" }, children: "Input \u2192 agent" }),
@@ -8074,7 +8094,7 @@ function AgentTraces({ debug, command, defaultExpanded = true }) {
8074
8094
  isStepExpanded && /* @__PURE__ */ jsxs3(Fragment2, { children: [
8075
8095
  t.reasoning && /* @__PURE__ */ jsxs3("div", { style: { marginBottom: "6px" }, children: [
8076
8096
  /* @__PURE__ */ jsx4("div", { style: { color: "#71717a", marginBottom: "2px" }, children: "Reasoning" }),
8077
- /* @__PURE__ */ jsx4("pre", { style: { margin: 0, padding: "6px", background: "#fef3c7", borderRadius: "4px", whiteSpace: "pre-wrap", wordBreak: "break-word", maxHeight: "100px", overflow: "auto", borderLeft: "3px solid #f59e0b" }, children: t.reasoning })
8097
+ /* @__PURE__ */ jsx4("pre", { style: { margin: 0, padding: "6px", background: "#fef3c7", borderRadius: "4px", whiteSpace: "pre-wrap", wordBreak: "break-word", maxHeight: "100px", overflow: "auto", borderLeft: "3px solid #f59e0b", color: "#451a03" }, children: t.reasoning })
8078
8098
  ] }),
8079
8099
  t.llmInput && /* @__PURE__ */ jsxs3(Fragment2, { children: [
8080
8100
  /* @__PURE__ */ jsxs3("div", { style: { marginBottom: "6px" }, children: [
@@ -8934,6 +8954,15 @@ function ModelNexChatBubble({
8934
8954
  children: /* @__PURE__ */ jsx4(BookOpenIcon, {})
8935
8955
  }
8936
8956
  ) }) }),
8957
+ messages.length > 0 && !(tourPlayback.isActive || onboardingPlayback.isActive) && /* @__PURE__ */ jsx4(Tooltip, { title: "Clear chat", children: /* @__PURE__ */ jsx4(
8958
+ "button",
8959
+ {
8960
+ onClick: clearChat,
8961
+ style: { padding: "8px", borderRadius: "10px", border: "none", background: "transparent", cursor: "pointer", color: "#71717a" },
8962
+ "aria-label": "Clear chat",
8963
+ children: /* @__PURE__ */ jsx4(TrashIcon, {})
8964
+ }
8965
+ ) }),
8937
8966
  /* @__PURE__ */ jsx4(Tooltip, { title: "Minimize", children: /* @__PURE__ */ jsx4(
8938
8967
  "button",
8939
8968
  {
@@ -10669,12 +10698,12 @@ var ModelNexProvider = ({
10669
10698
  children,
10670
10699
  websiteId,
10671
10700
  userProfile,
10701
+ toursApiBase,
10672
10702
  devMode
10673
10703
  }) => {
10674
10704
  const serverUrl = DEFAULT_SERVER_URL2;
10675
10705
  const commandUrl = void 0;
10676
10706
  const disableSocket = false;
10677
- const toursApiBase = void 0;
10678
10707
  const renderedChildren = children;
10679
10708
  const [activeAgentActions, setActiveAgentActions] = useState15(/* @__PURE__ */ new Set());
10680
10709
  const [stagingFields, setStagingFields] = useState15(/* @__PURE__ */ new Set());
@@ -10765,12 +10794,13 @@ var ModelNexProvider = ({
10765
10794
  setChatMessages,
10766
10795
  websiteId,
10767
10796
  userProfile,
10797
+ toursApiBase,
10768
10798
  voiceMuted,
10769
10799
  setVoiceMuted,
10770
10800
  socketId,
10771
10801
  devMode
10772
10802
  }),
10773
- [serverUrl, commandUrl, registerAction, unregisterAction, activeAgentActions, stagingFields, highlightActions, studioMode, recordingMode, extractedElements, tagStore, chatMessages, websiteId, userProfile, voiceMuted, socketId, devMode]
10803
+ [serverUrl, commandUrl, registerAction, unregisterAction, activeAgentActions, stagingFields, highlightActions, studioMode, recordingMode, extractedElements, tagStore, chatMessages, websiteId, userProfile, toursApiBase, voiceMuted, socketId, devMode]
10774
10804
  );
10775
10805
  return React8.createElement(
10776
10806
  ModelNexContext.Provider,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modelnex/sdk",
3
- "version": "0.5.8",
3
+ "version": "0.5.10",
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",