@thinkingos/vsl-mcp-server 0.4.1 → 0.4.3
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 +93 -42
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -73,6 +73,50 @@ import {
|
|
|
73
73
|
|
|
74
74
|
// src/tools/getSnapshot.ts
|
|
75
75
|
import { isVslDiff } from "@thinkingos/vsl-sdk";
|
|
76
|
+
|
|
77
|
+
// src/utils/injectVslIds.ts
|
|
78
|
+
async function injectVslIdsIntoDom(browser, objects) {
|
|
79
|
+
const page = await browser.getPage();
|
|
80
|
+
await page.waitForTimeout(50);
|
|
81
|
+
await browser.evaluate(
|
|
82
|
+
(objects2) => {
|
|
83
|
+
function parseVslId(id) {
|
|
84
|
+
const match = id.match(/^([a-z][a-z0-9]*(?:_[a-z][a-z0-9]*)*)_(\d+(?:_\d+)*)$/);
|
|
85
|
+
if (!match) return null;
|
|
86
|
+
const tag = match[1];
|
|
87
|
+
const indexPath = match[2].split("_").map(Number);
|
|
88
|
+
return { tag, indexPath };
|
|
89
|
+
}
|
|
90
|
+
function visit(obj) {
|
|
91
|
+
const parsed = parseVslId(obj.id);
|
|
92
|
+
if (!parsed) return;
|
|
93
|
+
const indexPath = parsed.indexPath;
|
|
94
|
+
let current = document.body;
|
|
95
|
+
for (const idx of indexPath) {
|
|
96
|
+
if (!current) break;
|
|
97
|
+
const elementChildren = Array.from(current.children);
|
|
98
|
+
current = elementChildren[idx] || null;
|
|
99
|
+
}
|
|
100
|
+
if (current) {
|
|
101
|
+
current.setAttribute("data-vsl-id", obj.id);
|
|
102
|
+
} else {
|
|
103
|
+
console.warn(`[VSL] Failed to inject data-vsl-id="${obj.id}": element not found at indexPath [${indexPath.join(", ")}]`);
|
|
104
|
+
}
|
|
105
|
+
if (obj.ch) {
|
|
106
|
+
for (const child of obj.ch) {
|
|
107
|
+
visit(child);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
for (const obj of objects2) {
|
|
112
|
+
visit(obj);
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
objects
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// src/tools/getSnapshot.ts
|
|
76
120
|
var DEFAULT_SNAPSHOT_TTL_MS = 5e3;
|
|
77
121
|
var snapshotCache = /* @__PURE__ */ new Map();
|
|
78
122
|
function filterObjectsByDetailLevel(objects, level) {
|
|
@@ -227,14 +271,25 @@ function extractDomTreeInBrowser() {
|
|
|
227
271
|
result.push(...collectVisibleChildren(child, path3));
|
|
228
272
|
return;
|
|
229
273
|
}
|
|
274
|
+
const attributes = extractAttributes(child);
|
|
275
|
+
const css = captureCss(child);
|
|
276
|
+
if (attributes["aria-hidden"] === "true") {
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
if (css.opacity === "0" && css.pointerEvents === "none") {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
const children = collectVisibleChildren(child, path3);
|
|
283
|
+
const vslId = `${tag}_${path3.join("_")}`;
|
|
284
|
+
child.setAttribute("data-vsl-id", vslId);
|
|
230
285
|
result.push({
|
|
231
286
|
tag,
|
|
232
287
|
indexPath: path3,
|
|
233
288
|
rect,
|
|
234
289
|
text: ownText(child) || null,
|
|
235
|
-
attributes
|
|
236
|
-
css
|
|
237
|
-
children
|
|
290
|
+
attributes,
|
|
291
|
+
css,
|
|
292
|
+
children
|
|
238
293
|
});
|
|
239
294
|
});
|
|
240
295
|
return result;
|
|
@@ -306,33 +361,7 @@ async function handleGetSnapshot(args, browser, session, _config) {
|
|
|
306
361
|
input
|
|
307
362
|
);
|
|
308
363
|
const currentDoc = isVslDiff(result) ? session.getSnapshot() : result;
|
|
309
|
-
await browser.
|
|
310
|
-
(objects) => {
|
|
311
|
-
function visit(obj) {
|
|
312
|
-
const parts = obj.id.split("_");
|
|
313
|
-
if (parts.length < 2) return;
|
|
314
|
-
const indexPath = parts.slice(1).map(Number);
|
|
315
|
-
let current = document.body;
|
|
316
|
-
for (const idx of indexPath) {
|
|
317
|
-
if (!current) break;
|
|
318
|
-
const elementChildren = Array.from(current.children);
|
|
319
|
-
current = elementChildren[idx] || null;
|
|
320
|
-
}
|
|
321
|
-
if (current) {
|
|
322
|
-
current.setAttribute("data-vsl-id", obj.id);
|
|
323
|
-
}
|
|
324
|
-
if (obj.ch) {
|
|
325
|
-
for (const child of obj.ch) {
|
|
326
|
-
visit(child);
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
for (const obj of objects) {
|
|
331
|
-
visit(obj);
|
|
332
|
-
}
|
|
333
|
-
},
|
|
334
|
-
currentDoc.objects
|
|
335
|
-
);
|
|
364
|
+
await injectVslIdsIntoDom(browser, currentDoc.objects);
|
|
336
365
|
const filteredObjects = filterObjectsByDetailLevel(currentDoc.objects, detailLevel);
|
|
337
366
|
const filteredResult = isVslDiff(result) ? { ...result, objects: filteredObjects } : { ...result, objects: filteredObjects };
|
|
338
367
|
const executionTimeMs = Date.now() - startTime;
|
|
@@ -461,6 +490,8 @@ async function handleNavigate(args, browser, session) {
|
|
|
461
490
|
};
|
|
462
491
|
session.snapshotFromElements(elements, input);
|
|
463
492
|
snapshot = session.getSnapshot();
|
|
493
|
+
const currentDoc = session.getSnapshot();
|
|
494
|
+
await injectVslIdsIntoDom(browser, currentDoc.objects);
|
|
464
495
|
} catch (error) {
|
|
465
496
|
const errorMessage = `Failed to extract snapshot: ${error instanceof Error ? error.message : String(error)}`;
|
|
466
497
|
console.error("[vsl_navigate]", errorMessage, error);
|
|
@@ -541,6 +572,7 @@ async function getStateAfterAction(session, browser, url) {
|
|
|
541
572
|
session.snapshotFromElements(elements, input);
|
|
542
573
|
const diff = session.getDiff();
|
|
543
574
|
const snapshot = session.getSnapshot();
|
|
575
|
+
await injectVslIdsIntoDom(browser, snapshot.objects);
|
|
544
576
|
return { diff, snapshot };
|
|
545
577
|
} catch (error) {
|
|
546
578
|
const errorMessage = `Failed to get state after action: ${error instanceof Error ? error.message : String(error)}`;
|
|
@@ -576,11 +608,26 @@ async function handleExecuteAction(args, browser, session) {
|
|
|
576
608
|
};
|
|
577
609
|
}
|
|
578
610
|
if (args.action === "scroll" && args.value !== void 0) {
|
|
579
|
-
const
|
|
580
|
-
|
|
611
|
+
const SCROLL_DIRECTIONS = /* @__PURE__ */ new Set(["up", "down", "left", "right"]);
|
|
612
|
+
const parts = args.value.trim().split(":");
|
|
613
|
+
const dir = parts[0] ?? "";
|
|
614
|
+
const amountPart = parts[1];
|
|
615
|
+
if (!SCROLL_DIRECTIONS.has(dir)) {
|
|
581
616
|
return {
|
|
582
617
|
status: "error",
|
|
583
|
-
error:
|
|
618
|
+
error: `Invalid scroll direction: "${dir}". Valid: up, down, left, right. Optional amount: "down:300"`
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
if (parts.length > 2) {
|
|
622
|
+
return {
|
|
623
|
+
status: "error",
|
|
624
|
+
error: 'Invalid scroll value format. Use "dir" or "dir:amount" (e.g. "down:300")'
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
if (amountPart !== void 0 && !/^\d+(?:\.\d+)?$/.test(amountPart)) {
|
|
628
|
+
return {
|
|
629
|
+
status: "error",
|
|
630
|
+
error: `Invalid scroll amount: "${amountPart}". Must be a positive number`
|
|
584
631
|
};
|
|
585
632
|
}
|
|
586
633
|
}
|
|
@@ -644,16 +691,20 @@ async function handleExecuteAction(args, browser, session) {
|
|
|
644
691
|
}
|
|
645
692
|
await page.fill(selector, args.value, { timeout: 5e3 });
|
|
646
693
|
break;
|
|
647
|
-
case "scroll":
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
694
|
+
case "scroll": {
|
|
695
|
+
const DEFAULT_SCROLL_AMOUNT = 500;
|
|
696
|
+
const scrollValue = args.value || "down";
|
|
697
|
+
const scrollParts = scrollValue.trim().split(":");
|
|
698
|
+
const scrollDir = scrollParts[0];
|
|
699
|
+
const scrollAmount = scrollParts[1] !== void 0 ? Number(scrollParts[1]) : DEFAULT_SCROLL_AMOUNT;
|
|
700
|
+
const dx = scrollDir === "left" ? -scrollAmount : scrollDir === "right" ? scrollAmount : 0;
|
|
701
|
+
const dy = scrollDir === "up" ? -scrollAmount : scrollDir === "down" ? scrollAmount : 0;
|
|
702
|
+
await browser.evaluate(({ dx: dx2, dy: dy2 }) => {
|
|
703
|
+
window.scrollBy(dx2, dy2);
|
|
704
|
+
}, { dx, dy });
|
|
655
705
|
await page.waitForTimeout(50);
|
|
656
706
|
break;
|
|
707
|
+
}
|
|
657
708
|
case "select":
|
|
658
709
|
if (!args.value) {
|
|
659
710
|
return {
|
|
@@ -1773,7 +1824,7 @@ var VSL_TOOLS = [
|
|
|
1773
1824
|
},
|
|
1774
1825
|
{
|
|
1775
1826
|
name: "vsl_execute_action",
|
|
1776
|
-
description:
|
|
1827
|
+
description: '\u0412\u044B\u043F\u043E\u043B\u043D\u0438\u0442\u044C \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u043D\u0430\u0434 \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u043E\u043C VSL. \u041D\u0430\u0439\u0434\u0438\u0442\u0435 \u044D\u043B\u0435\u043C\u0435\u043D\u0442 \u043F\u043E id \u0432 snapshot (vsl_get_snapshot), \u0437\u0430\u0442\u0435\u043C \u0432\u044B\u0437\u043E\u0432\u0438\u0442\u0435 \u044D\u0442\u043E \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435. \u041F\u043E\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043C\u044B\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044F: click (\u043A\u043B\u0438\u043A \u043F\u043E \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u0443), type (\u0432\u0432\u043E\u0434 \u0442\u0435\u043A\u0441\u0442\u0430, \u0442\u0440\u0435\u0431\u0443\u0435\u0442 value), fill (\u0430\u043B\u0438\u0430\u0441 type, \u0432\u0432\u043E\u0434 \u0442\u0435\u043A\u0441\u0442\u0430, \u0442\u0440\u0435\u0431\u0443\u0435\u0442 value), scroll (\u043F\u0440\u043E\u043A\u0440\u0443\u0442\u043A\u0430, \u0444\u043E\u0440\u043C\u0430\u0442: "up", "down", "left", "right" \u0438\u043B\u0438 "dir:amount", \u043D\u0430\u043F\u0440\u0438\u043C\u0435\u0440 "down:300"), select (\u0432\u044B\u0431\u043E\u0440 \u043E\u043F\u0446\u0438\u0438, \u0442\u0440\u0435\u0431\u0443\u0435\u0442 value), hover, focus, blur, check, uncheck, press (\u043D\u0430\u0436\u0430\u0442\u0438\u0435 \u043A\u043B\u0430\u0432\u0438\u0448\u0438), upload (\u0437\u0430\u0433\u0440\u0443\u0437\u043A\u0430 \u0444\u0430\u0439\u043B\u0430, \u0442\u0440\u0435\u0431\u0443\u0435\u0442 value \u2014 \u043F\u0443\u0442\u044C \u043A \u0444\u0430\u0439\u043B\u0443 \u0438\u043B\u0438 \u0441\u043F\u0438\u0441\u043E\u043A \u043F\u0443\u0442\u0435\u0439 \u0447\u0435\u0440\u0435\u0437 \u0437\u0430\u043F\u044F\u0442\u0443\u044E). \u041F\u0440\u0438\u043C\u0435\u0440: {action:click, target_id:btn_1} \u0438\u043B\u0438 {action:type, target_id:inp_2, value:hello@mail.com} \u0438\u043B\u0438 {action:fill, target_id:inp_2, value:hello@mail.com} \u0438\u043B\u0438 {action:upload, target_id:file_input_0, value:/path/to/file.pdf}. \u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440 return_state=true \u0432\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 diff \u0438 snapshot \u043F\u043E\u0441\u043B\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044F.',
|
|
1777
1828
|
inputSchema: {
|
|
1778
1829
|
type: "object",
|
|
1779
1830
|
properties: {
|