@thinkingos/vsl-mcp-server 1.2.15 → 1.2.17
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/README.md +10 -0
- package/dist/index.js +230 -17
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -347,6 +347,16 @@ Agent: vsl_get_snapshot(full=true)
|
|
|
347
347
|
│ ├── Diff Engine → VslDiff │
|
|
348
348
|
│ └── Vision Classifier (LLM flash models) │
|
|
349
349
|
└─────────────────────────────────────────────┘
|
|
350
|
+
## Исправления (Bug Fixes)
|
|
351
|
+
|
|
352
|
+
> **ID Stability после fill action** — элементы сохраняют свои короткие ID после изменений DOM.
|
|
353
|
+
|
|
354
|
+
> **Iframe ID Resolution** — исправлен резолв ID для элементов внутри iframe (используется полный `target_id` с префиксом `iframe_N:`).
|
|
355
|
+
|
|
356
|
+
> **Lazy Text Loading** — тексты длиннее ~200 символов автоматически заменяются на `txt_preview` + `txt_ref` для экономии токенов.
|
|
357
|
+
|
|
358
|
+
> **Lazy Navigation** — автоматическая навигация на URL перед выполнением действий, если браузер не на нужной странице.
|
|
359
|
+
|
|
350
360
|
## Требования
|
|
351
361
|
|
|
352
362
|
- Node.js ≥ 18
|
package/dist/index.js
CHANGED
|
@@ -232,36 +232,61 @@ function extractTag(longId) {
|
|
|
232
232
|
function toBase36(n) {
|
|
233
233
|
return n.toString(36);
|
|
234
234
|
}
|
|
235
|
-
function buildIdMap(objects) {
|
|
235
|
+
function buildIdMap(objects, previousReverseIdMap) {
|
|
236
236
|
const map = /* @__PURE__ */ new Map();
|
|
237
237
|
const counters = /* @__PURE__ */ new Map();
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
counters.set(prefix, counter + 1);
|
|
243
|
-
const shortId = framePrefix ? `${framePrefix}:${prefix}_${toBase36(counter)}` : `${prefix}_${toBase36(counter)}`;
|
|
244
|
-
map.set(shortId, obj.id);
|
|
238
|
+
const assignedShortIds = /* @__PURE__ */ new Set();
|
|
239
|
+
const elementsWithPrefix = [];
|
|
240
|
+
function collect(obj, framePrefix) {
|
|
241
|
+
elementsWithPrefix.push({ obj, framePrefix });
|
|
245
242
|
if (obj.ch) {
|
|
246
243
|
for (const child of obj.ch) {
|
|
247
|
-
|
|
244
|
+
collect(child, framePrefix);
|
|
248
245
|
}
|
|
249
246
|
}
|
|
250
247
|
if (obj.iframe?.vsl?.objects) {
|
|
251
248
|
const frameIndex = obj.iframe.frameId;
|
|
252
249
|
const iframeFramePrefix = `iframe_${frameIndex}`;
|
|
253
250
|
for (const iframeObj of obj.iframe.vsl.objects) {
|
|
254
|
-
|
|
251
|
+
collect(iframeObj, iframeFramePrefix);
|
|
255
252
|
}
|
|
256
253
|
}
|
|
257
254
|
}
|
|
258
255
|
for (const obj of objects) {
|
|
259
|
-
|
|
256
|
+
collect(obj);
|
|
257
|
+
}
|
|
258
|
+
if (previousReverseIdMap) {
|
|
259
|
+
for (const { obj, framePrefix } of elementsWithPrefix) {
|
|
260
|
+
const oldShortId = previousReverseIdMap.get(obj.id);
|
|
261
|
+
if (oldShortId && !assignedShortIds.has(oldShortId)) {
|
|
262
|
+
const expectedPrefix = framePrefix ? `${framePrefix}:` : "";
|
|
263
|
+
if (oldShortId.startsWith(expectedPrefix) || !framePrefix && !oldShortId.includes(":")) {
|
|
264
|
+
map.set(oldShortId, obj.id);
|
|
265
|
+
assignedShortIds.add(oldShortId);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
for (const { obj, framePrefix } of elementsWithPrefix) {
|
|
271
|
+
if (map.has(framePrefix ? `${framePrefix}:${obj.id}` : obj.id)) continue;
|
|
272
|
+
const alreadyAssigned = Array.from(map.entries()).some(([_, longId]) => longId === obj.id);
|
|
273
|
+
if (alreadyAssigned) continue;
|
|
274
|
+
const tag = extractTag(obj.id);
|
|
275
|
+
const prefix = tagPrefix(tag);
|
|
276
|
+
let counter = counters.get(prefix) ?? 0;
|
|
277
|
+
let shortId;
|
|
278
|
+
do {
|
|
279
|
+
shortId = framePrefix ? `${framePrefix}:${prefix}_${toBase36(counter)}` : `${prefix}_${toBase36(counter)}`;
|
|
280
|
+
counter++;
|
|
281
|
+
} while (assignedShortIds.has(shortId));
|
|
282
|
+
counters.set(prefix, counter);
|
|
283
|
+
assignedShortIds.add(shortId);
|
|
284
|
+
map.set(shortId, obj.id);
|
|
260
285
|
}
|
|
261
286
|
return map;
|
|
262
287
|
}
|
|
263
|
-
function buildReverseIdMap(objects) {
|
|
264
|
-
const forward = buildIdMap(objects);
|
|
288
|
+
function buildReverseIdMap(objects, previousReverseIdMap) {
|
|
289
|
+
const forward = buildIdMap(objects, previousReverseIdMap);
|
|
265
290
|
const reverse = /* @__PURE__ */ new Map();
|
|
266
291
|
for (const [shortId, longId] of forward) {
|
|
267
292
|
reverse.set(longId, shortId);
|
|
@@ -1249,7 +1274,7 @@ async function handleExecuteAction(args, browser, session) {
|
|
|
1249
1274
|
}
|
|
1250
1275
|
}
|
|
1251
1276
|
const idMap = session.getIdMap();
|
|
1252
|
-
const resolvedId = idMap.get(
|
|
1277
|
+
const resolvedId = idMap.get(args.target_id) || localShortId;
|
|
1253
1278
|
const localId = resolvedId;
|
|
1254
1279
|
const selector = `[data-vsl-id="${localId}"], #${localId}, .${localId}`;
|
|
1255
1280
|
const page = await browser.getPage();
|
|
@@ -2340,6 +2365,159 @@ async function handleGetTextBlock(args, session) {
|
|
|
2340
2365
|
}
|
|
2341
2366
|
}
|
|
2342
2367
|
|
|
2368
|
+
// src/tools/clickCoordinates.ts
|
|
2369
|
+
async function handleClickCoordinates(args, browser, session) {
|
|
2370
|
+
const startTime = Date.now();
|
|
2371
|
+
try {
|
|
2372
|
+
let findObjectById2 = function(objects, targetId) {
|
|
2373
|
+
for (const obj of objects) {
|
|
2374
|
+
const o = obj;
|
|
2375
|
+
if (o.id === targetId) return o;
|
|
2376
|
+
if (o.ch && Array.isArray(o.ch)) {
|
|
2377
|
+
const found = findObjectById2(o.ch, targetId);
|
|
2378
|
+
if (found) return found;
|
|
2379
|
+
}
|
|
2380
|
+
}
|
|
2381
|
+
return null;
|
|
2382
|
+
};
|
|
2383
|
+
var findObjectById = findObjectById2;
|
|
2384
|
+
if (!args.target_id || typeof args.target_id !== "string") {
|
|
2385
|
+
return { status: "error", error: "target_id is required" };
|
|
2386
|
+
}
|
|
2387
|
+
if (!args.clicks || !Array.isArray(args.clicks) || args.clicks.length === 0) {
|
|
2388
|
+
return { status: "error", error: "clicks array is required and must not be empty" };
|
|
2389
|
+
}
|
|
2390
|
+
for (let i = 0; i < args.clicks.length; i++) {
|
|
2391
|
+
const click = args.clicks[i];
|
|
2392
|
+
if (typeof click.x !== "number" || typeof click.y !== "number") {
|
|
2393
|
+
return { status: "error", error: `clicks[${i}]: x and y must be numbers` };
|
|
2394
|
+
}
|
|
2395
|
+
if (click.delay_after_ms !== void 0 && typeof click.delay_after_ms !== "number") {
|
|
2396
|
+
return { status: "error", error: `clicks[${i}]: delay_after_ms must be a number` };
|
|
2397
|
+
}
|
|
2398
|
+
}
|
|
2399
|
+
if (args.return_state !== void 0 && typeof args.return_state !== "boolean") {
|
|
2400
|
+
return { status: "error", error: "return_state must be a boolean (true or false)" };
|
|
2401
|
+
}
|
|
2402
|
+
if (!session.hasSnapshot()) {
|
|
2403
|
+
return {
|
|
2404
|
+
status: "error",
|
|
2405
|
+
error: "No snapshot available. Call vsl_get_snapshot first."
|
|
2406
|
+
};
|
|
2407
|
+
}
|
|
2408
|
+
const isAvailable = await browser.isAvailable();
|
|
2409
|
+
if (!isAvailable) {
|
|
2410
|
+
return {
|
|
2411
|
+
status: "error",
|
|
2412
|
+
error: "Playwright is not installed. Install it with: npm install playwright"
|
|
2413
|
+
};
|
|
2414
|
+
}
|
|
2415
|
+
const page = await browser.getPage();
|
|
2416
|
+
let targetFrame = null;
|
|
2417
|
+
let localShortId = args.target_id;
|
|
2418
|
+
const frameMatch = args.target_id.match(/^iframe_(\d+):(.+)$/);
|
|
2419
|
+
if (frameMatch) {
|
|
2420
|
+
const frameIndex = parseInt(frameMatch[1], 10);
|
|
2421
|
+
localShortId = frameMatch[2];
|
|
2422
|
+
const frameUrl = iframeFrameRegistry.get(frameIndex);
|
|
2423
|
+
if (!frameUrl) {
|
|
2424
|
+
return {
|
|
2425
|
+
status: "error",
|
|
2426
|
+
error: `Frame iframe_${frameIndex} not found in registry. Call vsl_get_snapshot first.`
|
|
2427
|
+
};
|
|
2428
|
+
}
|
|
2429
|
+
const frames = await browser.getFrames();
|
|
2430
|
+
targetFrame = frames.find((f) => {
|
|
2431
|
+
const u = f.url();
|
|
2432
|
+
return u === frameUrl || u.includes(frameUrl) || frameUrl.includes(u);
|
|
2433
|
+
}) || null;
|
|
2434
|
+
if (!targetFrame) {
|
|
2435
|
+
return {
|
|
2436
|
+
status: "error",
|
|
2437
|
+
error: `Frame with URL "${frameUrl}" not found. Available frames: ${frames.map((f) => f.url()).join(", ")}`
|
|
2438
|
+
};
|
|
2439
|
+
}
|
|
2440
|
+
}
|
|
2441
|
+
const idMap = session.getIdMap();
|
|
2442
|
+
const resolvedId = idMap.get(args.target_id) || localShortId;
|
|
2443
|
+
const snapshotDoc = session.getSnapshot();
|
|
2444
|
+
const snapshotObjects = snapshotDoc.objects ?? [];
|
|
2445
|
+
const snapshotObj = findObjectById2(snapshotObjects, resolvedId);
|
|
2446
|
+
if (!snapshotObj || !snapshotObj.rect) {
|
|
2447
|
+
return {
|
|
2448
|
+
status: "error",
|
|
2449
|
+
error: `Element "${args.target_id}" (resolved: "${resolvedId}") not found in snapshot or has no rect. Call vsl_get_snapshot first.`
|
|
2450
|
+
};
|
|
2451
|
+
}
|
|
2452
|
+
const elementRect = snapshotObj.rect;
|
|
2453
|
+
const target = targetFrame || page;
|
|
2454
|
+
let actionsCompleted = 0;
|
|
2455
|
+
for (const click of args.clicks) {
|
|
2456
|
+
const absoluteX = elementRect.x + click.x;
|
|
2457
|
+
const absoluteY = elementRect.y + click.y;
|
|
2458
|
+
const elementFound = await target.evaluate(
|
|
2459
|
+
([x, y]) => {
|
|
2460
|
+
const el = document.elementFromPoint(x, y);
|
|
2461
|
+
if (el) {
|
|
2462
|
+
el.click();
|
|
2463
|
+
return true;
|
|
2464
|
+
}
|
|
2465
|
+
return false;
|
|
2466
|
+
},
|
|
2467
|
+
[absoluteX, absoluteY]
|
|
2468
|
+
);
|
|
2469
|
+
if (!elementFound) {
|
|
2470
|
+
console.warn(`[vsl_click_coordinates] No element found at (${absoluteX}, ${absoluteY}), skipping`);
|
|
2471
|
+
}
|
|
2472
|
+
actionsCompleted++;
|
|
2473
|
+
if (click.delay_after_ms && click.delay_after_ms > 0) {
|
|
2474
|
+
await page.waitForTimeout(click.delay_after_ms);
|
|
2475
|
+
}
|
|
2476
|
+
}
|
|
2477
|
+
await page.waitForTimeout(100);
|
|
2478
|
+
const returnState = args.return_state !== false;
|
|
2479
|
+
const result = {
|
|
2480
|
+
status: "success",
|
|
2481
|
+
data: {
|
|
2482
|
+
actions_completed: actionsCompleted
|
|
2483
|
+
},
|
|
2484
|
+
metadata: computeToolMetrics(
|
|
2485
|
+
{ actions_completed: actionsCompleted, target_id: args.target_id },
|
|
2486
|
+
startTime
|
|
2487
|
+
)
|
|
2488
|
+
};
|
|
2489
|
+
if (returnState) {
|
|
2490
|
+
const currentUrl = await browser.evaluate(() => window.location.href);
|
|
2491
|
+
const state = await getStateAfterAction(session, browser, currentUrl);
|
|
2492
|
+
if (state.error) {
|
|
2493
|
+
result.data.diff = void 0;
|
|
2494
|
+
result.data.snapshot = void 0;
|
|
2495
|
+
} else {
|
|
2496
|
+
result.data.diff = state.diff;
|
|
2497
|
+
result.data.snapshot = state.snapshot;
|
|
2498
|
+
result.data.scrollable = state.scrollable;
|
|
2499
|
+
}
|
|
2500
|
+
try {
|
|
2501
|
+
const screenshotBuffer = await page.screenshot({ type: "png", fullPage: false });
|
|
2502
|
+
const base64Image = screenshotBuffer.toString("base64");
|
|
2503
|
+
result.data.screenshot = {
|
|
2504
|
+
type: "image",
|
|
2505
|
+
data: base64Image,
|
|
2506
|
+
mimeType: "image/png"
|
|
2507
|
+
};
|
|
2508
|
+
} catch (screenshotError) {
|
|
2509
|
+
console.error("[vsl_click_coordinates] Screenshot failed:", screenshotError);
|
|
2510
|
+
}
|
|
2511
|
+
}
|
|
2512
|
+
return result;
|
|
2513
|
+
} catch (error) {
|
|
2514
|
+
return {
|
|
2515
|
+
status: "error",
|
|
2516
|
+
error: `vsl_click_coordinates failed: ${error instanceof Error ? error.message : String(error)}`
|
|
2517
|
+
};
|
|
2518
|
+
}
|
|
2519
|
+
}
|
|
2520
|
+
|
|
2343
2521
|
// src/tools/index.ts
|
|
2344
2522
|
var VSL_TOOLS = [
|
|
2345
2523
|
{
|
|
@@ -2473,6 +2651,37 @@ var VSL_TOOLS = [
|
|
|
2473
2651
|
},
|
|
2474
2652
|
required: ["block_id"]
|
|
2475
2653
|
}
|
|
2654
|
+
},
|
|
2655
|
+
{
|
|
2656
|
+
name: "vsl_click_coordinates",
|
|
2657
|
+
description: '\u0412\u044B\u043F\u043E\u043B\u043D\u0438\u0442\u044C \u043C\u043D\u043E\u0436\u0435\u0441\u0442\u0432\u0435\u043D\u043D\u044B\u0435 \u043A\u043B\u0438\u043A\u0438 \u043F\u043E \u043A\u043E\u043E\u0440\u0434\u0438\u043D\u0430\u0442\u0430\u043C \u043E\u0442\u043D\u043E\u0441\u0438\u0442\u0435\u043B\u044C\u043D\u043E \u0446\u0435\u043B\u0435\u0432\u043E\u0433\u043E \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u0430. \u041A\u043E\u043E\u0440\u0434\u0438\u043D\u0430\u0442\u044B (x, y) \u0437\u0430\u0434\u0430\u044E\u0442\u0441\u044F \u0432 \u043F\u0438\u043A\u0441\u0435\u043B\u044F\u0445 \u043E\u0442 \u043B\u0435\u0432\u043E\u0433\u043E \u0432\u0435\u0440\u0445\u043D\u0435\u0433\u043E \u0443\u0433\u043B\u0430 \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u0430 (\u0438\u0441\u043F\u043E\u043B\u044C\u0437\u0443\u0439\u0442\u0435 bbox \u0438\u0437 snapshot). \u041F\u043E\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0437\u0430\u0434\u0435\u0440\u0436\u043A\u0438 \u043C\u0435\u0436\u0434\u0443 \u043A\u043B\u0438\u043A\u0430\u043C\u0438. \u0412\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 diff + snapshot + screenshot \u043F\u043E\u0441\u043B\u0435 \u0432\u0441\u0435\u0445 \u043A\u043B\u0438\u043A\u043E\u0432. \u041F\u0440\u0438\u043C\u0435\u0440: {target_id: "iframe_2", clicks: [{x: 50, y: 50, delay_after_ms: 500}, {x: 150, y: 50}]}.',
|
|
2658
|
+
inputSchema: {
|
|
2659
|
+
type: "object",
|
|
2660
|
+
properties: {
|
|
2661
|
+
target_id: {
|
|
2662
|
+
type: "string",
|
|
2663
|
+
description: "ID \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u0430 \u0432 VSL JSON (\u043D\u0430\u043F\u0440\u0438\u043C\u0435\u0440, iframe_2 \u0434\u043B\u044F reCAPTCHA challenge iframe)"
|
|
2664
|
+
},
|
|
2665
|
+
clicks: {
|
|
2666
|
+
type: "array",
|
|
2667
|
+
description: "\u041C\u0430\u0441\u0441\u0438\u0432 \u043A\u043B\u0438\u043A\u043E\u0432. \u041A\u0430\u0436\u0434\u044B\u0439 \u043A\u043B\u0438\u043A: {x: number, y: number, delay_after_ms?: number}. \u041A\u043E\u043E\u0440\u0434\u0438\u043D\u0430\u0442\u044B \u0432 \u043F\u0438\u043A\u0441\u0435\u043B\u044F\u0445 \u043E\u0442 \u043B\u0435\u0432\u043E\u0433\u043E \u0432\u0435\u0440\u0445\u043D\u0435\u0433\u043E \u0443\u0433\u043B\u0430 \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u0430.",
|
|
2668
|
+
items: {
|
|
2669
|
+
type: "object",
|
|
2670
|
+
properties: {
|
|
2671
|
+
x: { type: "number", description: "X \u043A\u043E\u043E\u0440\u0434\u0438\u043D\u0430\u0442\u0430 (pixels \u043E\u0442 \u043B\u0435\u0432\u043E\u0433\u043E \u043A\u0440\u0430\u044F \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u0430)" },
|
|
2672
|
+
y: { type: "number", description: "Y \u043A\u043E\u043E\u0440\u0434\u0438\u043D\u0430\u0442\u0430 (pixels \u043E\u0442 \u0432\u0435\u0440\u0445\u043D\u0435\u0433\u043E \u043A\u0440\u0430\u044F \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u0430)" },
|
|
2673
|
+
delay_after_ms: { type: "number", description: "\u0417\u0430\u0434\u0435\u0440\u0436\u043A\u0430 \u043F\u043E\u0441\u043B\u0435 \u043A\u043B\u0438\u043A\u0430 (\u043C\u0441)" }
|
|
2674
|
+
},
|
|
2675
|
+
required: ["x", "y"]
|
|
2676
|
+
}
|
|
2677
|
+
},
|
|
2678
|
+
return_state: {
|
|
2679
|
+
type: "boolean",
|
|
2680
|
+
description: "\u0415\u0441\u043B\u0438 true (default), \u0432\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 diff + snapshot + screenshot \u043F\u043E\u0441\u043B\u0435 \u0432\u0441\u0435\u0445 \u043A\u043B\u0438\u043A\u043E\u0432."
|
|
2681
|
+
}
|
|
2682
|
+
},
|
|
2683
|
+
required: ["target_id", "clicks"]
|
|
2684
|
+
}
|
|
2476
2685
|
}
|
|
2477
2686
|
];
|
|
2478
2687
|
function registerTools(server, config, sessionManager) {
|
|
@@ -2509,6 +2718,9 @@ function registerTools(server, config, sessionManager) {
|
|
|
2509
2718
|
case "vsl_get_text_block":
|
|
2510
2719
|
result = await handleGetTextBlock(args, session);
|
|
2511
2720
|
break;
|
|
2721
|
+
case "vsl_click_coordinates":
|
|
2722
|
+
result = await handleClickCoordinates(args, browser, session);
|
|
2723
|
+
break;
|
|
2512
2724
|
default:
|
|
2513
2725
|
return {
|
|
2514
2726
|
content: [
|
|
@@ -3030,16 +3242,17 @@ var ServerSession = class {
|
|
|
3030
3242
|
this.currentDocument = doc;
|
|
3031
3243
|
this.version += 1;
|
|
3032
3244
|
this.scrollContext = input.scroll ? { ...input.scroll } : null;
|
|
3245
|
+
const prevReverseIdMap = this.reverseIdMap;
|
|
3033
3246
|
const currentObjects = doc.objects ?? [];
|
|
3034
3247
|
const previousObjects = this.previousDocument?.objects ?? [];
|
|
3035
3248
|
const unionObjects = [...currentObjects, ...previousObjects];
|
|
3036
3249
|
if (currentObjects.length > 0) {
|
|
3037
|
-
this.idMap = buildIdMap(currentObjects);
|
|
3250
|
+
this.idMap = buildIdMap(currentObjects, prevReverseIdMap);
|
|
3038
3251
|
} else {
|
|
3039
3252
|
this.idMap = /* @__PURE__ */ new Map();
|
|
3040
3253
|
}
|
|
3041
3254
|
if (unionObjects.length > 0) {
|
|
3042
|
-
this.reverseIdMap = buildReverseIdMap(unionObjects);
|
|
3255
|
+
this.reverseIdMap = buildReverseIdMap(unionObjects, prevReverseIdMap);
|
|
3043
3256
|
} else {
|
|
3044
3257
|
this.reverseIdMap = /* @__PURE__ */ new Map();
|
|
3045
3258
|
}
|
|
@@ -3293,7 +3506,7 @@ var SessionManager = class {
|
|
|
3293
3506
|
};
|
|
3294
3507
|
|
|
3295
3508
|
// src/version.ts
|
|
3296
|
-
var VSL_MCP_SERVER_VERSION = "1.2.
|
|
3509
|
+
var VSL_MCP_SERVER_VERSION = "1.2.17";
|
|
3297
3510
|
|
|
3298
3511
|
// src/index.ts
|
|
3299
3512
|
async function main() {
|