@thinkingos/vsl-mcp-server 1.2.11 → 1.2.13
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 +61 -10
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
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
|
|
|
@@ -705,9 +730,9 @@ async function handleGetSnapshot(args, browser, session, _config) {
|
|
|
705
730
|
const iframeElementsRaw = await browser.evaluate(extractIframesInBrowser);
|
|
706
731
|
const iframeElements = Array.isArray(iframeElementsRaw) ? iframeElementsRaw : [];
|
|
707
732
|
if (iframeElements.length > 0) {
|
|
708
|
-
console.
|
|
733
|
+
console.error(`[VSL] Found ${iframeElements.length} iframe elements:`);
|
|
709
734
|
for (const iframe of iframeElements) {
|
|
710
|
-
console.
|
|
735
|
+
console.error(` - URL: ${iframe.url}, name: ${iframe.name}, id: ${iframe.id}`);
|
|
711
736
|
}
|
|
712
737
|
}
|
|
713
738
|
const iframeSubDocs = [];
|
|
@@ -721,10 +746,10 @@ async function handleGetSnapshot(args, browser, session, _config) {
|
|
|
721
746
|
});
|
|
722
747
|
if (!frame) {
|
|
723
748
|
console.warn(`[VSL] No Playwright frame found for iframe URL: ${iframeInfo.url}`);
|
|
724
|
-
console.
|
|
749
|
+
console.error(`[VSL] Available frames:`, allFrames.map((f) => f.url()));
|
|
725
750
|
continue;
|
|
726
751
|
}
|
|
727
|
-
console.
|
|
752
|
+
console.error(`[VSL] \u2705 Matched Playwright frame for iframe: ${iframeInfo.url} \u2192 ${frame.url()}`);
|
|
728
753
|
const iframeExtraction = await extractDomTreeFromFrame(browser, frame);
|
|
729
754
|
const iframeViewport = iframeExtraction.viewport;
|
|
730
755
|
const { segmentTree: segmentTree2, buildVslDocument: buildVslDocument2 } = await import("@thinkingos/vsl-sdk");
|
|
@@ -743,7 +768,7 @@ async function handleGetSnapshot(args, browser, session, _config) {
|
|
|
743
768
|
// сохраняем PlaywrightFrame для injectVslIdsIntoFrame
|
|
744
769
|
});
|
|
745
770
|
iframeFrameRegistry.set(iframeSubDocs.length - 1, iframeInfo.url);
|
|
746
|
-
console.
|
|
771
|
+
console.error(`[VSL] \u2705 Successfully extracted DOM from iframe: ${iframeInfo.url} (${iframeDoc.objects.length} objects)`);
|
|
747
772
|
} catch (error) {
|
|
748
773
|
console.warn(`[VSL] \u274C Failed to extract iframe ${iframeInfo.url}:`, error);
|
|
749
774
|
}
|
|
@@ -761,7 +786,7 @@ async function handleGetSnapshot(args, browser, session, _config) {
|
|
|
761
786
|
);
|
|
762
787
|
const currentDoc = isVslDiff(result) ? session.getSnapshot() : result;
|
|
763
788
|
if (iframeSubDocs.length > 0) {
|
|
764
|
-
console.
|
|
789
|
+
console.error(`[VSL] Adding ${iframeSubDocs.length} iframe objects to snapshot`);
|
|
765
790
|
const iframeObjects = iframeSubDocs.map((iframeInfo, index) => ({
|
|
766
791
|
id: `iframe_${index}`,
|
|
767
792
|
t: "iframe",
|
|
@@ -774,6 +799,7 @@ async function handleGetSnapshot(args, browser, session, _config) {
|
|
|
774
799
|
}
|
|
775
800
|
}));
|
|
776
801
|
currentDoc.objects.push(...iframeObjects);
|
|
802
|
+
session.rebuildIdMaps();
|
|
777
803
|
for (const iframeInfo of iframeSubDocs) {
|
|
778
804
|
await injectVslIdsIntoFrame(browser, iframeInfo.frame, iframeInfo.doc.objects);
|
|
779
805
|
}
|
|
@@ -2987,6 +3013,31 @@ var ServerSession = class {
|
|
|
2987
3013
|
getReverseIdMap() {
|
|
2988
3014
|
return this.reverseIdMap;
|
|
2989
3015
|
}
|
|
3016
|
+
/**
|
|
3017
|
+
* Перестраивает карты маппинга ID (idMap и reverseIdMap) на основе текущего документа.
|
|
3018
|
+
* Используется после добавления iframe объектов в currentDoc.objects,
|
|
3019
|
+
* чтобы reverseIdMap содержал маппинг для iframe элементов.
|
|
3020
|
+
*
|
|
3021
|
+
* Context: snapshotFromElements() строит карты ДО добавления iframe объектов,
|
|
3022
|
+
* поэтому iframe элементы не попадают в reverseIdMap. Этот метод вызывается
|
|
3023
|
+
* после добавления iframe объектов для перестроения карт.
|
|
3024
|
+
*/
|
|
3025
|
+
rebuildIdMaps() {
|
|
3026
|
+
if (!this.currentDocument) return;
|
|
3027
|
+
const currentObjects = this.currentDocument.objects ?? [];
|
|
3028
|
+
const previousObjects = this.previousDocument?.objects ?? [];
|
|
3029
|
+
const unionObjects = [...currentObjects, ...previousObjects];
|
|
3030
|
+
if (currentObjects.length > 0) {
|
|
3031
|
+
this.idMap = buildIdMap(currentObjects);
|
|
3032
|
+
} else {
|
|
3033
|
+
this.idMap = /* @__PURE__ */ new Map();
|
|
3034
|
+
}
|
|
3035
|
+
if (unionObjects.length > 0) {
|
|
3036
|
+
this.reverseIdMap = buildReverseIdMap(unionObjects);
|
|
3037
|
+
} else {
|
|
3038
|
+
this.reverseIdMap = /* @__PURE__ */ new Map();
|
|
3039
|
+
}
|
|
3040
|
+
}
|
|
2990
3041
|
};
|
|
2991
3042
|
|
|
2992
3043
|
// src/session/sessionManager.ts
|
|
@@ -3119,7 +3170,7 @@ var SessionManager = class {
|
|
|
3119
3170
|
};
|
|
3120
3171
|
|
|
3121
3172
|
// src/version.ts
|
|
3122
|
-
var VSL_MCP_SERVER_VERSION = "1.2.
|
|
3173
|
+
var VSL_MCP_SERVER_VERSION = "1.2.13";
|
|
3123
3174
|
|
|
3124
3175
|
// src/index.ts
|
|
3125
3176
|
async function main() {
|