@thinkingos/vsl-mcp-server 1.2.10 → 1.2.12

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
@@ -185,16 +185,23 @@ function toBase36(n) {
185
185
  function buildIdMap(objects) {
186
186
  const map = /* @__PURE__ */ new Map();
187
187
  const counters = /* @__PURE__ */ new Map();
188
- function visit(obj) {
188
+ function visit(obj, framePrefix) {
189
189
  const tag = extractTag(obj.id);
190
190
  const prefix = tagPrefix(tag);
191
191
  const counter = counters.get(prefix) ?? 0;
192
192
  counters.set(prefix, counter + 1);
193
- const shortId = `${prefix}_${toBase36(counter)}`;
193
+ const shortId = framePrefix ? `${framePrefix}:${prefix}_${toBase36(counter)}` : `${prefix}_${toBase36(counter)}`;
194
194
  map.set(shortId, obj.id);
195
195
  if (obj.ch) {
196
196
  for (const child of obj.ch) {
197
- visit(child);
197
+ visit(child, framePrefix);
198
+ }
199
+ }
200
+ if (obj.iframe?.vsl?.objects) {
201
+ const frameIndex = obj.iframe.frameId;
202
+ const iframeFramePrefix = `iframe_${frameIndex}`;
203
+ for (const iframeObj of obj.iframe.vsl.objects) {
204
+ visit(iframeObj, iframeFramePrefix);
198
205
  }
199
206
  }
200
207
  }
@@ -219,6 +226,15 @@ function replaceIdsInDocument(document2, longToShort) {
219
226
  if (obj.ch) {
220
227
  result.ch = obj.ch.map(replaceObj);
221
228
  }
229
+ if (obj.iframe?.vsl?.objects) {
230
+ result.iframe = {
231
+ ...obj.iframe,
232
+ vsl: {
233
+ ...obj.iframe.vsl,
234
+ objects: obj.iframe.vsl.objects.map(replaceObj)
235
+ }
236
+ };
237
+ }
222
238
  return result;
223
239
  }
224
240
  return { ...document2, objects: document2.objects.map(replaceObj) };
@@ -266,6 +282,15 @@ function replaceIdsInVslObject(obj, reverseIdMap) {
266
282
  if (obj.ch && obj.ch.length > 0) {
267
283
  result.ch = obj.ch.map((child) => replaceIdsInVslObject(child, reverseIdMap));
268
284
  }
285
+ if (obj.iframe?.vsl?.objects) {
286
+ result.iframe = {
287
+ ...obj.iframe,
288
+ vsl: {
289
+ ...obj.iframe.vsl,
290
+ objects: obj.iframe.vsl.objects.map((child) => replaceIdsInVslObject(child, reverseIdMap))
291
+ }
292
+ };
293
+ }
269
294
  return result;
270
295
  }
271
296
 
@@ -447,6 +472,7 @@ function filterDiffByViewport(diff, nextDoc, prevDoc, win) {
447
472
  // src/tools/getSnapshot.ts
448
473
  var DEFAULT_SNAPSHOT_TTL_MS = 5e3;
449
474
  var snapshotCache = /* @__PURE__ */ new Map();
475
+ var iframeFrameRegistry = /* @__PURE__ */ new Map();
450
476
  function countObjects(objects) {
451
477
  let count = 0;
452
478
  for (const obj of objects) {
@@ -741,6 +767,7 @@ async function handleGetSnapshot(args, browser, session, _config) {
741
767
  frame
742
768
  // сохраняем PlaywrightFrame для injectVslIdsIntoFrame
743
769
  });
770
+ iframeFrameRegistry.set(iframeSubDocs.length - 1, iframeInfo.url);
744
771
  console.log(`[VSL] \u2705 Successfully extracted DOM from iframe: ${iframeInfo.url} (${iframeDoc.objects.length} objects)`);
745
772
  } catch (error) {
746
773
  console.warn(`[VSL] \u274C Failed to extract iframe ${iframeInfo.url}:`, error);
@@ -1124,12 +1151,22 @@ async function handleExecuteAction(args, browser, session) {
1124
1151
  if (frameMatch) {
1125
1152
  const frameIndex = parseInt(frameMatch[1], 10);
1126
1153
  localId = frameMatch[2];
1154
+ const frameUrl = iframeFrameRegistry.get(frameIndex);
1155
+ if (!frameUrl) {
1156
+ return {
1157
+ status: "error",
1158
+ error: `Frame iframe_${frameIndex} not found in registry. Call vsl_get_snapshot first.`
1159
+ };
1160
+ }
1127
1161
  const frames = await browser.getFrames();
1128
- targetFrame = frames[frameIndex + 1] || null;
1162
+ targetFrame = frames.find((f) => {
1163
+ const u = f.url();
1164
+ return u === frameUrl || u.includes(frameUrl) || frameUrl.includes(u);
1165
+ }) || null;
1129
1166
  if (!targetFrame) {
1130
1167
  return {
1131
1168
  status: "error",
1132
- error: `Frame iframe_${frameIndex} not found. Available frames: ${frames.length}`
1169
+ error: `Frame with URL "${frameUrl}" not found. Available frames: ${frames.map((f) => f.url()).join(", ")}`
1133
1170
  };
1134
1171
  }
1135
1172
  }
@@ -3107,7 +3144,7 @@ var SessionManager = class {
3107
3144
  };
3108
3145
 
3109
3146
  // src/version.ts
3110
- var VSL_MCP_SERVER_VERSION = "1.2.10";
3147
+ var VSL_MCP_SERVER_VERSION = "1.2.12";
3111
3148
 
3112
3149
  // src/index.ts
3113
3150
  async function main() {