@modelnex/sdk 0.5.7 → 0.5.8

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
@@ -315,7 +315,8 @@ interface TagData {
315
315
  interface TagStore {
316
316
  tags: Map<string, TagData>;
317
317
  getTag: (fingerprint: string) => TagData | undefined;
318
- setTag: (fingerprint: string, description: string, category?: TagData['category'], metadata?: Record<string, unknown>, selector?: string, patternId?: string, behavior?: string, sourcePage?: string, displayContext?: string) => void;
318
+ setTag: (fingerprint: string, description: string, category?: TagData['category'], metadata?: Record<string, unknown>, selector?: string, patternId?: string, behavior?: string, sourcePage?: string, displayContext?: string, skipRemoteSync?: boolean) => void;
319
+ setTagsBatch: (tags: TagData[], skipRemoteSync?: boolean) => void;
319
320
  deleteTag: (fingerprint: string) => void;
320
321
  getAllTags: () => TagData[];
321
322
  /** Export all tags as a JSON string (for debugging / backup) */
package/dist/index.d.ts CHANGED
@@ -315,7 +315,8 @@ interface TagData {
315
315
  interface TagStore {
316
316
  tags: Map<string, TagData>;
317
317
  getTag: (fingerprint: string) => TagData | undefined;
318
- setTag: (fingerprint: string, description: string, category?: TagData['category'], metadata?: Record<string, unknown>, selector?: string, patternId?: string, behavior?: string, sourcePage?: string, displayContext?: string) => void;
318
+ setTag: (fingerprint: string, description: string, category?: TagData['category'], metadata?: Record<string, unknown>, selector?: string, patternId?: string, behavior?: string, sourcePage?: string, displayContext?: string, skipRemoteSync?: boolean) => void;
319
+ setTagsBatch: (tags: TagData[], skipRemoteSync?: boolean) => void;
319
320
  deleteTag: (fingerprint: string) => void;
320
321
  getAllTags: () => TagData[];
321
322
  /** Export all tags as a JSON string (for debugging / backup) */
package/dist/index.js CHANGED
@@ -1272,7 +1272,7 @@ function useTagStore(options) {
1272
1272
  const getTag = (0, import_react6.useCallback)((fingerprint) => {
1273
1273
  return tags.get(fingerprint);
1274
1274
  }, [tags]);
1275
- const setTag = (0, import_react6.useCallback)((fingerprint, description, category, metadata, selector, patternId, behavior, sourcePage, displayContext) => {
1275
+ const setTag = (0, import_react6.useCallback)((fingerprint, description, category, metadata, selector, patternId, behavior, sourcePage, displayContext, skipRemoteSync) => {
1276
1276
  setTags((prev) => {
1277
1277
  const next = new Map(prev);
1278
1278
  const key = selector ? `selector:${selector}` : fingerprint;
@@ -1292,7 +1292,7 @@ function useTagStore(options) {
1292
1292
  updatedAt: now
1293
1293
  };
1294
1294
  next.set(key, tagObj);
1295
- if (apiUrl) {
1295
+ if (apiUrl && !skipRemoteSync) {
1296
1296
  const payload = { tags: [tagObj] };
1297
1297
  if (websiteId) payload.websiteId = websiteId;
1298
1298
  fetch(apiUrl, {
@@ -1304,6 +1304,34 @@ function useTagStore(options) {
1304
1304
  return next;
1305
1305
  });
1306
1306
  }, [apiUrl, websiteId]);
1307
+ const setTagsBatch = (0, import_react6.useCallback)((newTags, skipRemoteSync) => {
1308
+ setTags((prev) => {
1309
+ const next = new Map(prev);
1310
+ const now = (/* @__PURE__ */ new Date()).toISOString();
1311
+ const updatedTags = [];
1312
+ for (const t of newTags) {
1313
+ const key = t.selector ? `selector:${t.selector}` : t.fingerprint;
1314
+ const existing = prev.get(key);
1315
+ const tagObj = {
1316
+ ...t,
1317
+ createdAt: existing?.createdAt ?? t.createdAt ?? now,
1318
+ updatedAt: now
1319
+ };
1320
+ next.set(key, tagObj);
1321
+ updatedTags.push(tagObj);
1322
+ }
1323
+ if (apiUrl && !skipRemoteSync && updatedTags.length > 0) {
1324
+ const payload = { tags: updatedTags };
1325
+ if (websiteId) payload.websiteId = websiteId;
1326
+ fetch(apiUrl, {
1327
+ method: "POST",
1328
+ headers: { "Content-Type": "application/json" },
1329
+ body: JSON.stringify(payload)
1330
+ }).catch((err) => console.warn("[ModelNex] Failed to save remote tags batch:", err));
1331
+ }
1332
+ return next;
1333
+ });
1334
+ }, [apiUrl, websiteId]);
1307
1335
  const deleteTag = (0, import_react6.useCallback)((fingerprint) => {
1308
1336
  setTags((prev) => {
1309
1337
  const next = new Map(prev);
@@ -1333,7 +1361,7 @@ function useTagStore(options) {
1333
1361
  console.warn("[ModelNex] Failed to import tags:", err);
1334
1362
  }
1335
1363
  }, []);
1336
- return { tags, getTag, setTag, deleteTag, getAllTags, exportTags, importTags };
1364
+ return { tags, getTag, setTag, setTagsBatch, deleteTag, getAllTags, exportTags, importTags };
1337
1365
  }
1338
1366
 
1339
1367
  // src/studio-mode.tsx
@@ -8480,21 +8508,7 @@ function ModelNexChatBubble({
8480
8508
  });
8481
8509
  const data = await resp.json();
8482
8510
  if (data.success && Array.isArray(data.tags)) {
8483
- for (const tag of data.tags) {
8484
- if (tag.patternId && tag.description && tag.selector) {
8485
- tagStore.setTag(
8486
- "",
8487
- tag.description,
8488
- tag.category || "other",
8489
- { matchedFingerprints: tag.matchedFingerprints },
8490
- tag.selector,
8491
- tag.patternId,
8492
- tag.behavior || void 0,
8493
- tag.sourcePage || void 0,
8494
- tag.displayContext || void 0
8495
- );
8496
- }
8497
- }
8511
+ tagStore.setTagsBatch(data.tags, true);
8498
8512
  lastAutoTaggedUrlRef.current = currentUrl;
8499
8513
  localStorage.setItem(storageKey, "true");
8500
8514
  console.log(`[ModelNex] Auto-tagged ${data.tags.length} elements for ${currentUrl}`);
package/dist/index.mjs CHANGED
@@ -1063,7 +1063,7 @@ function useTagStore(options) {
1063
1063
  const getTag = useCallback3((fingerprint) => {
1064
1064
  return tags.get(fingerprint);
1065
1065
  }, [tags]);
1066
- const setTag = useCallback3((fingerprint, description, category, metadata, selector, patternId, behavior, sourcePage, displayContext) => {
1066
+ const setTag = useCallback3((fingerprint, description, category, metadata, selector, patternId, behavior, sourcePage, displayContext, skipRemoteSync) => {
1067
1067
  setTags((prev) => {
1068
1068
  const next = new Map(prev);
1069
1069
  const key = selector ? `selector:${selector}` : fingerprint;
@@ -1083,7 +1083,7 @@ function useTagStore(options) {
1083
1083
  updatedAt: now
1084
1084
  };
1085
1085
  next.set(key, tagObj);
1086
- if (apiUrl) {
1086
+ if (apiUrl && !skipRemoteSync) {
1087
1087
  const payload = { tags: [tagObj] };
1088
1088
  if (websiteId) payload.websiteId = websiteId;
1089
1089
  fetch(apiUrl, {
@@ -1095,6 +1095,34 @@ function useTagStore(options) {
1095
1095
  return next;
1096
1096
  });
1097
1097
  }, [apiUrl, websiteId]);
1098
+ const setTagsBatch = useCallback3((newTags, skipRemoteSync) => {
1099
+ setTags((prev) => {
1100
+ const next = new Map(prev);
1101
+ const now = (/* @__PURE__ */ new Date()).toISOString();
1102
+ const updatedTags = [];
1103
+ for (const t of newTags) {
1104
+ const key = t.selector ? `selector:${t.selector}` : t.fingerprint;
1105
+ const existing = prev.get(key);
1106
+ const tagObj = {
1107
+ ...t,
1108
+ createdAt: existing?.createdAt ?? t.createdAt ?? now,
1109
+ updatedAt: now
1110
+ };
1111
+ next.set(key, tagObj);
1112
+ updatedTags.push(tagObj);
1113
+ }
1114
+ if (apiUrl && !skipRemoteSync && updatedTags.length > 0) {
1115
+ const payload = { tags: updatedTags };
1116
+ if (websiteId) payload.websiteId = websiteId;
1117
+ fetch(apiUrl, {
1118
+ method: "POST",
1119
+ headers: { "Content-Type": "application/json" },
1120
+ body: JSON.stringify(payload)
1121
+ }).catch((err) => console.warn("[ModelNex] Failed to save remote tags batch:", err));
1122
+ }
1123
+ return next;
1124
+ });
1125
+ }, [apiUrl, websiteId]);
1098
1126
  const deleteTag = useCallback3((fingerprint) => {
1099
1127
  setTags((prev) => {
1100
1128
  const next = new Map(prev);
@@ -1124,7 +1152,7 @@ function useTagStore(options) {
1124
1152
  console.warn("[ModelNex] Failed to import tags:", err);
1125
1153
  }
1126
1154
  }, []);
1127
- return { tags, getTag, setTag, deleteTag, getAllTags, exportTags, importTags };
1155
+ return { tags, getTag, setTag, setTagsBatch, deleteTag, getAllTags, exportTags, importTags };
1128
1156
  }
1129
1157
 
1130
1158
  // src/studio-mode.tsx
@@ -8270,21 +8298,7 @@ function ModelNexChatBubble({
8270
8298
  });
8271
8299
  const data = await resp.json();
8272
8300
  if (data.success && Array.isArray(data.tags)) {
8273
- for (const tag of data.tags) {
8274
- if (tag.patternId && tag.description && tag.selector) {
8275
- tagStore.setTag(
8276
- "",
8277
- tag.description,
8278
- tag.category || "other",
8279
- { matchedFingerprints: tag.matchedFingerprints },
8280
- tag.selector,
8281
- tag.patternId,
8282
- tag.behavior || void 0,
8283
- tag.sourcePage || void 0,
8284
- tag.displayContext || void 0
8285
- );
8286
- }
8287
- }
8301
+ tagStore.setTagsBatch(data.tags, true);
8288
8302
  lastAutoTaggedUrlRef.current = currentUrl;
8289
8303
  localStorage.setItem(storageKey, "true");
8290
8304
  console.log(`[ModelNex] Auto-tagged ${data.tags.length} elements for ${currentUrl}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modelnex/sdk",
3
- "version": "0.5.7",
3
+ "version": "0.5.8",
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",