@thinkingos/vsl-mcp-server 1.1.3 → 1.2.1
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 +58 -21
- package/dist/index.js +381 -393
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -189,12 +189,78 @@ function filterObjectsByDetailLevel(objects, level, options) {
|
|
|
189
189
|
}
|
|
190
190
|
return objects.map(filterRecursive).filter((obj) => obj !== null);
|
|
191
191
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
if (!
|
|
196
|
-
|
|
197
|
-
|
|
192
|
+
|
|
193
|
+
// src/utils/viewportFilter.ts
|
|
194
|
+
function computeVisibleWindow(viewport, scroll) {
|
|
195
|
+
if (!scroll) {
|
|
196
|
+
return { x: 0, y: 0, width: viewport.width, height: viewport.height };
|
|
197
|
+
}
|
|
198
|
+
return { x: scroll.x, y: scroll.y, width: viewport.width, height: viewport.height };
|
|
199
|
+
}
|
|
200
|
+
function computeScrollable(viewport, scroll) {
|
|
201
|
+
if (!scroll) {
|
|
202
|
+
return { top: false, bottom: false };
|
|
203
|
+
}
|
|
204
|
+
return {
|
|
205
|
+
top: scroll.y > 0,
|
|
206
|
+
bottom: scroll.y + viewport.height < scroll.height
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
function isVisible(p, s, win) {
|
|
210
|
+
return p[0] < win.x + win.width && p[0] + s[0] > win.x && p[1] < win.y + win.height && p[1] + s[1] > win.y;
|
|
211
|
+
}
|
|
212
|
+
function filterObjectsByViewport(objects, win) {
|
|
213
|
+
function filterRecursive(obj) {
|
|
214
|
+
const noCoords = !obj.p || !obj.s;
|
|
215
|
+
const selfVisible = noCoords || isVisible(obj.p, obj.s, win);
|
|
216
|
+
let filteredChildren = null;
|
|
217
|
+
if (obj.ch && obj.ch.length > 0) {
|
|
218
|
+
filteredChildren = obj.ch.map(filterRecursive).filter((child) => child !== null);
|
|
219
|
+
}
|
|
220
|
+
if (selfVisible) {
|
|
221
|
+
if (filteredChildren && obj.ch && filteredChildren.length !== obj.ch.length) {
|
|
222
|
+
const copy = { ...obj };
|
|
223
|
+
if (filteredChildren.length > 0) {
|
|
224
|
+
copy.ch = filteredChildren;
|
|
225
|
+
} else {
|
|
226
|
+
delete copy.ch;
|
|
227
|
+
}
|
|
228
|
+
return copy;
|
|
229
|
+
}
|
|
230
|
+
return obj;
|
|
231
|
+
}
|
|
232
|
+
if (filteredChildren && filteredChildren.length > 0) {
|
|
233
|
+
return { ...obj, ch: filteredChildren };
|
|
234
|
+
}
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
return objects.map(filterRecursive).filter((obj) => obj !== null);
|
|
238
|
+
}
|
|
239
|
+
function collectVisibleIds(objects, win, acc = /* @__PURE__ */ new Set()) {
|
|
240
|
+
for (const obj of objects) {
|
|
241
|
+
if (!obj.p || !obj.s || isVisible(obj.p, obj.s, win)) {
|
|
242
|
+
acc.add(obj.id);
|
|
243
|
+
}
|
|
244
|
+
if (obj.ch && obj.ch.length > 0) {
|
|
245
|
+
collectVisibleIds(obj.ch, win, acc);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return acc;
|
|
249
|
+
}
|
|
250
|
+
function filterDiffByViewport(diff, nextDoc, prevDoc, win) {
|
|
251
|
+
const nextVisible = collectVisibleIds(nextDoc.objects, win);
|
|
252
|
+
const prevVisible = prevDoc ? collectVisibleIds(prevDoc.objects, win) : null;
|
|
253
|
+
return {
|
|
254
|
+
...diff,
|
|
255
|
+
changes: {
|
|
256
|
+
added: filterObjectsByViewport(diff.changes.added, win),
|
|
257
|
+
modified: diff.changes.modified.filter((m) => nextVisible.has(m.id)),
|
|
258
|
+
removed: diff.changes.removed.filter(
|
|
259
|
+
(r) => prevVisible ? prevVisible.has(r.id) : true
|
|
260
|
+
),
|
|
261
|
+
unchanged_refs: diff.changes.unchanged_refs.filter((id) => nextVisible.has(id))
|
|
262
|
+
}
|
|
263
|
+
};
|
|
198
264
|
}
|
|
199
265
|
|
|
200
266
|
// src/tools/getSnapshot.ts
|
|
@@ -210,11 +276,9 @@ function countObjects(objects) {
|
|
|
210
276
|
}
|
|
211
277
|
return count;
|
|
212
278
|
}
|
|
213
|
-
function extractDomTreeInBrowser(
|
|
214
|
-
const includeOffscreen = options?.includeOffscreen ?? false;
|
|
279
|
+
function extractDomTreeInBrowser() {
|
|
215
280
|
const viewportWidth = window.innerWidth;
|
|
216
281
|
const viewportHeight = window.innerHeight;
|
|
217
|
-
let culledCount = 0;
|
|
218
282
|
const NON_RENDERABLE_TAGS = /* @__PURE__ */ new Set([
|
|
219
283
|
"script",
|
|
220
284
|
"style",
|
|
@@ -278,45 +342,43 @@ function extractDomTreeInBrowser(options) {
|
|
|
278
342
|
return css;
|
|
279
343
|
}
|
|
280
344
|
function toRect(rect) {
|
|
281
|
-
return {
|
|
345
|
+
return {
|
|
346
|
+
x: rect.x + window.scrollX,
|
|
347
|
+
y: rect.y + window.scrollY,
|
|
348
|
+
width: rect.width,
|
|
349
|
+
height: rect.height
|
|
350
|
+
};
|
|
282
351
|
}
|
|
283
352
|
function hasZeroBox(rect) {
|
|
284
353
|
return rect.width <= 0 || rect.height <= 0;
|
|
285
354
|
}
|
|
286
|
-
function isInViewport(rect) {
|
|
287
|
-
return rect.y < viewportHeight && rect.y + rect.height > 0;
|
|
288
|
-
}
|
|
289
355
|
function collectVisibleChildren(parent, parentPath) {
|
|
290
356
|
const result = [];
|
|
291
357
|
Array.from(parent.children).forEach((child, index) => {
|
|
292
|
-
const
|
|
358
|
+
const path2 = [...parentPath, index];
|
|
293
359
|
const tag = child.tagName.toLowerCase();
|
|
294
360
|
if (NON_RENDERABLE_TAGS.has(tag) || isDisplayNone(child)) {
|
|
295
361
|
return;
|
|
296
362
|
}
|
|
297
363
|
const rect = toRect(child.getBoundingClientRect());
|
|
298
364
|
if (isVisibilityHidden(child) || hasZeroBox(rect)) {
|
|
299
|
-
result.push(...collectVisibleChildren(child,
|
|
365
|
+
result.push(...collectVisibleChildren(child, path2));
|
|
300
366
|
return;
|
|
301
367
|
}
|
|
302
368
|
const attributes = extractAttributes(child);
|
|
303
369
|
const css = captureCss(child);
|
|
304
|
-
if (attributes["aria-hidden"] === "true") {
|
|
370
|
+
if (attributes?.["aria-hidden"] === "true") {
|
|
305
371
|
return;
|
|
306
372
|
}
|
|
307
373
|
if (css.opacity === "0" && css.pointerEvents === "none") {
|
|
308
374
|
return;
|
|
309
375
|
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
return;
|
|
313
|
-
}
|
|
314
|
-
const children = collectVisibleChildren(child, path3);
|
|
315
|
-
const vslId = `${tag}_${path3.join("_")}`;
|
|
376
|
+
const children = collectVisibleChildren(child, path2);
|
|
377
|
+
const vslId = `${tag}_${path2.join("_")}`;
|
|
316
378
|
child.setAttribute("data-vsl-id", vslId);
|
|
317
379
|
result.push({
|
|
318
380
|
tag,
|
|
319
|
-
indexPath:
|
|
381
|
+
indexPath: path2,
|
|
320
382
|
rect,
|
|
321
383
|
text: ownText(child) || null,
|
|
322
384
|
attributes,
|
|
@@ -332,10 +394,25 @@ function extractDomTreeInBrowser(options) {
|
|
|
332
394
|
return [{
|
|
333
395
|
__type: "extraction_result",
|
|
334
396
|
elements,
|
|
335
|
-
|
|
336
|
-
|
|
397
|
+
viewport: { width: viewportWidth, height: viewportHeight },
|
|
398
|
+
scroll: {
|
|
399
|
+
x: window.scrollX,
|
|
400
|
+
y: window.scrollY,
|
|
401
|
+
width: document.documentElement ? document.documentElement.scrollWidth : 0,
|
|
402
|
+
height: document.documentElement ? document.documentElement.scrollHeight : 0
|
|
403
|
+
}
|
|
337
404
|
}];
|
|
338
405
|
}
|
|
406
|
+
async function extractDomTree(browser) {
|
|
407
|
+
const extractionResult = await browser.evaluate(
|
|
408
|
+
extractDomTreeInBrowser
|
|
409
|
+
);
|
|
410
|
+
const extraction = Array.isArray(extractionResult) ? extractionResult[0] : void 0;
|
|
411
|
+
if (!extraction || !Array.isArray(extraction.elements)) {
|
|
412
|
+
throw new Error("Failed to extract DOM tree: empty result");
|
|
413
|
+
}
|
|
414
|
+
return extraction;
|
|
415
|
+
}
|
|
339
416
|
async function handleGetSnapshot(args, browser, session, _config) {
|
|
340
417
|
const startTime = Date.now();
|
|
341
418
|
const detailLevel = args.detail_level || "medium";
|
|
@@ -355,18 +432,35 @@ async function handleGetSnapshot(args, browser, session, _config) {
|
|
|
355
432
|
}
|
|
356
433
|
try {
|
|
357
434
|
if (ttl > 0) {
|
|
358
|
-
const cacheKey =
|
|
435
|
+
const cacheKey = args.url || "current";
|
|
359
436
|
const cached = snapshotCache.get(cacheKey);
|
|
360
437
|
if (cached && Date.now() - cached.timestamp < ttl) {
|
|
438
|
+
const scrollable2 = computeScrollable(cached.fullDocument.canvas.viewport, cached.scrollContext);
|
|
439
|
+
const filteredObjects2 = args.full ? cached.fullDocument.objects : filterObjectsByDetailLevel(
|
|
440
|
+
filterObjectsByViewport(
|
|
441
|
+
cached.fullDocument.objects,
|
|
442
|
+
computeVisibleWindow(cached.fullDocument.canvas.viewport, cached.scrollContext)
|
|
443
|
+
),
|
|
444
|
+
detailLevel
|
|
445
|
+
);
|
|
446
|
+
const filteredResult2 = { ...cached.fullDocument, objects: filteredObjects2 };
|
|
447
|
+
const executionTimeMs2 = Date.now() - startTime;
|
|
448
|
+
const resultJson2 = JSON.stringify(filteredResult2);
|
|
449
|
+
const jsonSizeBytes2 = Buffer.byteLength(resultJson2, "utf-8");
|
|
450
|
+
const estimatedTokens2 = Math.ceil(jsonSizeBytes2 / 4);
|
|
451
|
+
const objectCount2 = countObjects(filteredObjects2);
|
|
452
|
+
const totalObjectsCount2 = countObjects(cached.fullDocument.objects);
|
|
361
453
|
return {
|
|
362
|
-
|
|
454
|
+
status: "success",
|
|
455
|
+
data: filteredResult2,
|
|
363
456
|
metadata: {
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
457
|
+
json_size_bytes: jsonSizeBytes2,
|
|
458
|
+
estimated_tokens: estimatedTokens2,
|
|
459
|
+
object_count: objectCount2,
|
|
460
|
+
total_objects_count: totalObjectsCount2,
|
|
461
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
462
|
+
execution_time_ms: executionTimeMs2,
|
|
463
|
+
scrollable: scrollable2
|
|
370
464
|
}
|
|
371
465
|
};
|
|
372
466
|
}
|
|
@@ -381,26 +475,8 @@ async function handleGetSnapshot(args, browser, session, _config) {
|
|
|
381
475
|
error: "Playwright is not installed. Install it with: npm install playwright"
|
|
382
476
|
};
|
|
383
477
|
}
|
|
384
|
-
const
|
|
385
|
-
const extractionResult = await browser.evaluate(
|
|
386
|
-
(opts) => extractDomTreeInBrowser(opts),
|
|
387
|
-
{ includeOffscreen }
|
|
388
|
-
);
|
|
389
|
-
if (!extractionResult || extractionResult.length === 0) {
|
|
390
|
-
return {
|
|
391
|
-
status: "error",
|
|
392
|
-
error: "Failed to extract DOM tree: empty result"
|
|
393
|
-
};
|
|
394
|
-
}
|
|
395
|
-
const extraction = extractionResult[0];
|
|
396
|
-
if (!extraction) {
|
|
397
|
-
return {
|
|
398
|
-
status: "error",
|
|
399
|
-
error: "Failed to extract DOM tree: extraction result is undefined"
|
|
400
|
-
};
|
|
401
|
-
}
|
|
478
|
+
const extraction = await extractDomTree(browser);
|
|
402
479
|
const extractedElements = extraction.elements;
|
|
403
|
-
const culledCount = extraction.culled_count;
|
|
404
480
|
const viewport = extraction.viewport;
|
|
405
481
|
const url = args.url || await browser.evaluate(() => window.location.href);
|
|
406
482
|
const title = await browser.evaluate(() => document.title);
|
|
@@ -408,7 +484,8 @@ async function handleGetSnapshot(args, browser, session, _config) {
|
|
|
408
484
|
viewport,
|
|
409
485
|
url,
|
|
410
486
|
title,
|
|
411
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
487
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
488
|
+
scroll: extraction.scroll
|
|
412
489
|
};
|
|
413
490
|
const result = session.snapshotFromElements(
|
|
414
491
|
extractedElements,
|
|
@@ -416,14 +493,18 @@ async function handleGetSnapshot(args, browser, session, _config) {
|
|
|
416
493
|
);
|
|
417
494
|
const currentDoc = isVslDiff(result) ? session.getSnapshot() : result;
|
|
418
495
|
await injectVslIdsIntoDom(browser, currentDoc.objects);
|
|
419
|
-
const
|
|
420
|
-
const
|
|
496
|
+
const scrollContext = session.getScrollContext();
|
|
497
|
+
const win = computeVisibleWindow(currentDoc.canvas.viewport, scrollContext);
|
|
498
|
+
const scrollable = computeScrollable(currentDoc.canvas.viewport, scrollContext);
|
|
499
|
+
const viewportFiltered = filterObjectsByViewport(currentDoc.objects, win);
|
|
500
|
+
const filteredObjects = args.full ? currentDoc.objects : filterObjectsByDetailLevel(viewportFiltered, detailLevel);
|
|
501
|
+
const filteredResult = isVslDiff(result) && !args.full ? filterDiffByViewport(result, currentDoc, session.getPreviousSnapshot(), win) : { ...currentDoc, objects: filteredObjects };
|
|
421
502
|
const executionTimeMs = Date.now() - startTime;
|
|
422
503
|
const resultJson = JSON.stringify(filteredResult);
|
|
423
504
|
const jsonSizeBytes = Buffer.byteLength(resultJson, "utf-8");
|
|
424
505
|
const estimatedTokens = Math.ceil(jsonSizeBytes / 4);
|
|
425
506
|
const objectCount = countObjects(filteredObjects);
|
|
426
|
-
const totalObjectsCount =
|
|
507
|
+
const totalObjectsCount = countObjects(currentDoc.objects);
|
|
427
508
|
const metadata = {
|
|
428
509
|
json_size_bytes: jsonSizeBytes,
|
|
429
510
|
estimated_tokens: estimatedTokens,
|
|
@@ -431,20 +512,15 @@ async function handleGetSnapshot(args, browser, session, _config) {
|
|
|
431
512
|
total_objects_count: totalObjectsCount,
|
|
432
513
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
433
514
|
execution_time_ms: executionTimeMs,
|
|
434
|
-
|
|
515
|
+
scrollable
|
|
435
516
|
};
|
|
436
517
|
if (ttl > 0) {
|
|
437
|
-
const cacheKey =
|
|
438
|
-
const resultToCache = {
|
|
439
|
-
status: "success",
|
|
440
|
-
data: filteredResult,
|
|
441
|
-
metadata
|
|
442
|
-
};
|
|
518
|
+
const cacheKey = args.url || "current";
|
|
443
519
|
snapshotCache.set(cacheKey, {
|
|
444
|
-
|
|
520
|
+
fullDocument: currentDoc,
|
|
521
|
+
scrollContext: session.getScrollContext(),
|
|
445
522
|
timestamp: Date.now(),
|
|
446
|
-
url: args.url || "current"
|
|
447
|
-
detailLevel
|
|
523
|
+
url: args.url || "current"
|
|
448
524
|
});
|
|
449
525
|
}
|
|
450
526
|
return {
|
|
@@ -474,36 +550,6 @@ function computeToolMetrics(result, startTime) {
|
|
|
474
550
|
};
|
|
475
551
|
}
|
|
476
552
|
|
|
477
|
-
// src/tools/getDiff.ts
|
|
478
|
-
async function handleGetDiff(session) {
|
|
479
|
-
const startTime = Date.now();
|
|
480
|
-
try {
|
|
481
|
-
if (!session.hasSnapshot()) {
|
|
482
|
-
return {
|
|
483
|
-
status: "error",
|
|
484
|
-
error: "No snapshot available. Call vsl_get_snapshot first."
|
|
485
|
-
};
|
|
486
|
-
}
|
|
487
|
-
const diff = session.getDiff();
|
|
488
|
-
if (!diff) {
|
|
489
|
-
return {
|
|
490
|
-
status: "error",
|
|
491
|
-
error: "No previous snapshot to compare against. This is the first snapshot."
|
|
492
|
-
};
|
|
493
|
-
}
|
|
494
|
-
return {
|
|
495
|
-
status: "success",
|
|
496
|
-
data: diff,
|
|
497
|
-
metadata: computeToolMetrics(diff, startTime)
|
|
498
|
-
};
|
|
499
|
-
} catch (error) {
|
|
500
|
-
return {
|
|
501
|
-
status: "error",
|
|
502
|
-
error: `vsl_get_diff failed: ${error instanceof Error ? error.message : String(error)}`
|
|
503
|
-
};
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
|
|
507
553
|
// src/tools/navigate.ts
|
|
508
554
|
async function handleNavigate(args, browser, session) {
|
|
509
555
|
const startTime = Date.now();
|
|
@@ -533,22 +579,25 @@ async function handleNavigate(args, browser, session) {
|
|
|
533
579
|
const title = await browser.evaluate(() => document.title);
|
|
534
580
|
let snapshot;
|
|
535
581
|
let snapshotWarning;
|
|
582
|
+
let scrollableMeta;
|
|
536
583
|
try {
|
|
537
|
-
const
|
|
538
|
-
const viewport = await browser.evaluate(() => ({
|
|
539
|
-
width: window.innerWidth,
|
|
540
|
-
height: window.innerHeight
|
|
541
|
-
}));
|
|
584
|
+
const extraction = await extractDomTree(browser);
|
|
542
585
|
const input = {
|
|
543
|
-
viewport,
|
|
586
|
+
viewport: extraction.viewport,
|
|
544
587
|
url: args.url,
|
|
545
588
|
title,
|
|
546
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
589
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
590
|
+
scroll: extraction.scroll
|
|
547
591
|
};
|
|
548
|
-
session.snapshotFromElements(elements, input);
|
|
549
|
-
snapshot = session.getSnapshot();
|
|
592
|
+
session.snapshotFromElements(extraction.elements, input);
|
|
550
593
|
const currentDoc = session.getSnapshot();
|
|
551
594
|
await injectVslIdsIntoDom(browser, currentDoc.objects);
|
|
595
|
+
const scrollContext = session.getScrollContext();
|
|
596
|
+
const win = computeVisibleWindow(currentDoc.canvas.viewport, scrollContext);
|
|
597
|
+
scrollableMeta = computeScrollable(currentDoc.canvas.viewport, scrollContext);
|
|
598
|
+
const viewportFiltered = filterObjectsByViewport(currentDoc.objects, win);
|
|
599
|
+
const filteredObjects = filterObjectsByDetailLevel(viewportFiltered, "medium");
|
|
600
|
+
snapshot = { ...currentDoc, objects: filteredObjects };
|
|
552
601
|
} catch (error) {
|
|
553
602
|
const errorMessage = `Failed to extract snapshot: ${error instanceof Error ? error.message : String(error)}`;
|
|
554
603
|
console.error("[vsl_navigate]", errorMessage, error);
|
|
@@ -562,7 +611,7 @@ async function handleNavigate(args, browser, session) {
|
|
|
562
611
|
const result = {
|
|
563
612
|
status: "success",
|
|
564
613
|
data,
|
|
565
|
-
metadata: computeToolMetrics(data, startTime)
|
|
614
|
+
metadata: { ...computeToolMetrics(data, startTime), scrollable: scrollableMeta }
|
|
566
615
|
};
|
|
567
616
|
if (snapshotWarning) {
|
|
568
617
|
result.warning = snapshotWarning;
|
|
@@ -615,28 +664,63 @@ var VALID_ACTIONS = [
|
|
|
615
664
|
];
|
|
616
665
|
async function getStateAfterAction(session, browser, url) {
|
|
617
666
|
try {
|
|
618
|
-
const
|
|
619
|
-
const viewport = await browser.evaluate(() => ({
|
|
620
|
-
width: window.innerWidth,
|
|
621
|
-
height: window.innerHeight
|
|
622
|
-
}));
|
|
667
|
+
const extraction = await extractDomTree(browser);
|
|
623
668
|
const input = {
|
|
624
|
-
viewport,
|
|
669
|
+
viewport: extraction.viewport,
|
|
625
670
|
url,
|
|
626
671
|
title: "",
|
|
627
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
672
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
673
|
+
scroll: extraction.scroll
|
|
628
674
|
};
|
|
629
|
-
session.snapshotFromElements(elements, input);
|
|
675
|
+
session.snapshotFromElements(extraction.elements, input);
|
|
676
|
+
const fullDoc = session.getSnapshot();
|
|
677
|
+
await injectVslIdsIntoDom(browser, fullDoc.objects);
|
|
678
|
+
const scrollContext = session.getScrollContext();
|
|
679
|
+
const win = computeVisibleWindow(fullDoc.canvas.viewport, scrollContext);
|
|
680
|
+
const scrollable = computeScrollable(fullDoc.canvas.viewport, scrollContext);
|
|
630
681
|
const diff = session.getDiff();
|
|
631
|
-
const
|
|
632
|
-
|
|
633
|
-
|
|
682
|
+
const filteredDiff = diff ? filterDiffByViewport(diff, fullDoc, session.getPreviousSnapshot(), win) : diff;
|
|
683
|
+
const viewportFiltered = filterObjectsByViewport(fullDoc.objects, win);
|
|
684
|
+
const filteredObjects = filterObjectsByDetailLevel(viewportFiltered, "medium");
|
|
685
|
+
const snapshot = { ...fullDoc, objects: filteredObjects };
|
|
686
|
+
return { diff: filteredDiff, snapshot, scrollable };
|
|
634
687
|
} catch (error) {
|
|
635
688
|
const errorMessage = `Failed to get state after action: ${error instanceof Error ? error.message : String(error)}`;
|
|
636
689
|
console.error("[vsl_execute_action]", errorMessage, error);
|
|
637
690
|
return { error: errorMessage };
|
|
638
691
|
}
|
|
639
692
|
}
|
|
693
|
+
function serverSideScrollFallback(prev, dx, dy, viewport) {
|
|
694
|
+
const width = prev?.width ?? 0;
|
|
695
|
+
const height = prev?.height ?? 0;
|
|
696
|
+
const maxX = Math.max(0, width - (viewport?.width ?? 0));
|
|
697
|
+
const maxY = Math.max(0, height - (viewport?.height ?? 0));
|
|
698
|
+
return {
|
|
699
|
+
x: Math.min(Math.max(0, (prev?.x ?? 0) + dx), maxX),
|
|
700
|
+
y: Math.min(Math.max(0, (prev?.y ?? 0) + dy), maxY),
|
|
701
|
+
width,
|
|
702
|
+
height
|
|
703
|
+
};
|
|
704
|
+
}
|
|
705
|
+
function buildScrollStateFromCache(session, scrollContext) {
|
|
706
|
+
try {
|
|
707
|
+
const fullDoc = session.getSnapshot();
|
|
708
|
+
const viewport = fullDoc.canvas?.viewport;
|
|
709
|
+
if (!viewport || typeof viewport.width !== "number" || typeof viewport.height !== "number") {
|
|
710
|
+
return { snapshot: fullDoc };
|
|
711
|
+
}
|
|
712
|
+
const win = computeVisibleWindow(viewport, scrollContext);
|
|
713
|
+
const scrollable = computeScrollable(viewport, scrollContext);
|
|
714
|
+
const viewportFiltered = filterObjectsByViewport(fullDoc.objects ?? [], win);
|
|
715
|
+
const filteredObjects = filterObjectsByDetailLevel(viewportFiltered, "medium");
|
|
716
|
+
const snapshot = { ...fullDoc, objects: filteredObjects };
|
|
717
|
+
return { snapshot, scrollable };
|
|
718
|
+
} catch (error) {
|
|
719
|
+
const errorMessage = `Failed to build scroll state from cache: ${error instanceof Error ? error.message : String(error)}`;
|
|
720
|
+
console.error("[vsl_execute_action]", errorMessage, error);
|
|
721
|
+
return { error: errorMessage };
|
|
722
|
+
}
|
|
723
|
+
}
|
|
640
724
|
async function handleExecuteAction(args, browser, session) {
|
|
641
725
|
const startTime = Date.now();
|
|
642
726
|
try {
|
|
@@ -721,15 +805,16 @@ async function handleExecuteAction(args, browser, session) {
|
|
|
721
805
|
return document.querySelector("[data-vsl-id]") !== null;
|
|
722
806
|
});
|
|
723
807
|
if (!hasVslIds) {
|
|
724
|
-
const
|
|
725
|
-
const viewport = await browser.evaluate(() => ({ width: window.innerWidth, height: window.innerHeight }));
|
|
808
|
+
const extraction = await extractDomTree(browser);
|
|
726
809
|
const input = {
|
|
727
|
-
viewport,
|
|
810
|
+
viewport: extraction.viewport,
|
|
728
811
|
url: snapshotUrl || "",
|
|
729
812
|
title: "",
|
|
730
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
813
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
814
|
+
// Метаданные скролла для единого пайплайна отдачи (АС[3])
|
|
815
|
+
scroll: extraction.scroll
|
|
731
816
|
};
|
|
732
|
-
session.snapshotFromElements(elements, input);
|
|
817
|
+
session.snapshotFromElements(extraction.elements, input);
|
|
733
818
|
}
|
|
734
819
|
const selector = `[data-vsl-id="${args.target_id}"], #${args.target_id}, .${args.target_id}`;
|
|
735
820
|
const page = await browser.getPage();
|
|
@@ -760,7 +845,44 @@ async function handleExecuteAction(args, browser, session) {
|
|
|
760
845
|
window.scrollBy(dx2, dy2);
|
|
761
846
|
}, { dx, dy });
|
|
762
847
|
await page.waitForTimeout(50);
|
|
763
|
-
|
|
848
|
+
const prevScroll = session.getScrollContext();
|
|
849
|
+
let newScroll = null;
|
|
850
|
+
try {
|
|
851
|
+
const raw = await browser.evaluate(() => ({
|
|
852
|
+
x: window.scrollX,
|
|
853
|
+
y: window.scrollY,
|
|
854
|
+
width: document.documentElement.scrollWidth,
|
|
855
|
+
height: document.documentElement.scrollHeight
|
|
856
|
+
}));
|
|
857
|
+
const r = raw;
|
|
858
|
+
if (r !== null && typeof r === "object" && typeof r.x === "number" && typeof r.y === "number" && typeof r.width === "number" && typeof r.height === "number") {
|
|
859
|
+
newScroll = r;
|
|
860
|
+
}
|
|
861
|
+
} catch {
|
|
862
|
+
}
|
|
863
|
+
if (!newScroll) {
|
|
864
|
+
newScroll = serverSideScrollFallback(prevScroll, dx, dy, session.getSnapshot().canvas?.viewport);
|
|
865
|
+
}
|
|
866
|
+
session.setScrollContext(newScroll);
|
|
867
|
+
const scrollResult = {
|
|
868
|
+
status: "success",
|
|
869
|
+
data: {
|
|
870
|
+
action: args.action,
|
|
871
|
+
target_id: args.target_id,
|
|
872
|
+
success: true
|
|
873
|
+
}
|
|
874
|
+
};
|
|
875
|
+
if (args.return_state !== false) {
|
|
876
|
+
const state = buildScrollStateFromCache(session, newScroll);
|
|
877
|
+
if (scrollResult.data) {
|
|
878
|
+
scrollResult.data.state = state;
|
|
879
|
+
if (state.error) {
|
|
880
|
+
scrollResult.warning = `State extraction failed: ${state.error}`;
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
scrollResult.metadata = computeToolMetrics(scrollResult.data, startTime);
|
|
885
|
+
return scrollResult;
|
|
764
886
|
}
|
|
765
887
|
case "select":
|
|
766
888
|
if (!args.value) {
|
|
@@ -807,50 +929,69 @@ async function handleExecuteAction(args, browser, session) {
|
|
|
807
929
|
break;
|
|
808
930
|
}
|
|
809
931
|
case "download": {
|
|
932
|
+
const downloadsBefore = browser.getDownloads();
|
|
810
933
|
if (args.value) {
|
|
811
|
-
|
|
934
|
+
await browser.evaluate((url) => {
|
|
812
935
|
const a = document.createElement("a");
|
|
813
936
|
a.href = url;
|
|
814
937
|
a.download = "";
|
|
815
938
|
document.body.appendChild(a);
|
|
816
939
|
a.click();
|
|
817
940
|
document.body.removeChild(a);
|
|
818
|
-
const id = `download_${Date.now()}_${Math.random().toString(36).slice(2)}`;
|
|
819
|
-
return id;
|
|
820
941
|
}, args.value);
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
942
|
+
} else {
|
|
943
|
+
await browser.evaluate((sel) => {
|
|
944
|
+
const el = document.querySelector(sel);
|
|
945
|
+
if (el) el.click();
|
|
946
|
+
}, selector);
|
|
947
|
+
}
|
|
948
|
+
const pollDeadline = Date.now() + 5e3;
|
|
949
|
+
let newDownload;
|
|
950
|
+
while (!newDownload && Date.now() < pollDeadline) {
|
|
951
|
+
newDownload = browser.getDownloads().find(
|
|
952
|
+
(d) => !downloadsBefore.some((b) => b.downloadId === d.downloadId)
|
|
953
|
+
);
|
|
954
|
+
if (!newDownload) {
|
|
955
|
+
await browser.evaluate(() => new Promise((resolve) => setTimeout(resolve, 50)));
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
if (!newDownload) {
|
|
959
|
+
return {
|
|
960
|
+
status: "error",
|
|
961
|
+
error: "Download not detected after click (timeout 5000ms). The page may navigate instead of downloading."
|
|
835
962
|
};
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
963
|
+
}
|
|
964
|
+
const downloadInfo = await browser.waitForDownload(newDownload.downloadId, args.timeout);
|
|
965
|
+
if (args.save_path) {
|
|
966
|
+
await browser.saveDownload(downloadInfo.downloadId, args.save_path);
|
|
967
|
+
}
|
|
968
|
+
const result2 = {
|
|
969
|
+
status: "success",
|
|
970
|
+
data: {
|
|
971
|
+
action: args.action,
|
|
972
|
+
target_id: args.target_id,
|
|
973
|
+
success: downloadInfo.status === "completed",
|
|
974
|
+
download: {
|
|
975
|
+
downloadId: downloadInfo.downloadId,
|
|
976
|
+
filename: downloadInfo.filename,
|
|
977
|
+
url: downloadInfo.url,
|
|
978
|
+
status: downloadInfo.status,
|
|
979
|
+
path: args.save_path ?? downloadInfo.path ?? void 0
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
};
|
|
983
|
+
if (args.return_state !== false) {
|
|
984
|
+
const currentUrl = await browser.evaluate(() => window.location.href);
|
|
985
|
+
const state = await getStateAfterAction(session, browser, currentUrl);
|
|
986
|
+
if (result2.data) {
|
|
987
|
+
result2.data.state = state;
|
|
988
|
+
if (state.error) {
|
|
989
|
+
result2.warning = `State extraction failed: ${state.error}`;
|
|
844
990
|
}
|
|
845
991
|
}
|
|
846
|
-
result2.metadata = computeToolMetrics(result2.data, startTime);
|
|
847
|
-
return result2;
|
|
848
992
|
}
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
if (el) el.click();
|
|
852
|
-
}, selector);
|
|
853
|
-
break;
|
|
993
|
+
result2.metadata = computeToolMetrics(result2.data, startTime);
|
|
994
|
+
return result2;
|
|
854
995
|
}
|
|
855
996
|
case "upload": {
|
|
856
997
|
if (!args.value) {
|
|
@@ -1015,8 +1156,8 @@ async function handleGetVisual(args, browser, session) {
|
|
|
1015
1156
|
const rect2 = el.getBoundingClientRect();
|
|
1016
1157
|
const viewportWidth = window.innerWidth;
|
|
1017
1158
|
const viewportHeight = window.innerHeight;
|
|
1018
|
-
const
|
|
1019
|
-
if (
|
|
1159
|
+
const isVisible2 = rect2.top >= 0 && rect2.left >= 0 && rect2.bottom <= viewportHeight && rect2.right <= viewportWidth;
|
|
1160
|
+
if (isVisible2) {
|
|
1020
1161
|
return { needsScroll: false, scrolled: false };
|
|
1021
1162
|
}
|
|
1022
1163
|
el.scrollIntoView({ block: "center", inline: "center", behavior: "instant" });
|
|
@@ -1406,21 +1547,39 @@ async function handleReadPage(args, browser, session, _config) {
|
|
|
1406
1547
|
await browser.navigate(args.url);
|
|
1407
1548
|
const html = await browser.getContent();
|
|
1408
1549
|
const isSpa = detectSpa(html);
|
|
1409
|
-
const vslDocument = await extractVslFromPage(browser);
|
|
1410
1550
|
const hadPreviousSnapshot2 = session.hasSnapshot();
|
|
1411
|
-
|
|
1551
|
+
try {
|
|
1552
|
+
const extraction = await extractDomTree(browser);
|
|
1553
|
+
session.snapshotFromElements(extraction.elements, {
|
|
1554
|
+
viewport: extraction.viewport,
|
|
1555
|
+
url: args.url,
|
|
1556
|
+
title: extractTitle(html) || "",
|
|
1557
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1558
|
+
scroll: extraction.scroll
|
|
1559
|
+
});
|
|
1560
|
+
await injectVslIdsIntoDom(browser, session.getSnapshot().objects);
|
|
1561
|
+
} catch (extractError) {
|
|
1562
|
+
console.error("[vsl_read_page] SDK extraction failed, falling back to legacy extraction:", extractError);
|
|
1563
|
+
const fallbackDoc = await extractVslFromPage(browser);
|
|
1564
|
+
session.setSnapshot(fallbackDoc);
|
|
1565
|
+
}
|
|
1412
1566
|
const hasDiff2 = hadPreviousSnapshot2;
|
|
1413
1567
|
const readableHtml = readable ? applyReadableFilter(html) : html;
|
|
1414
1568
|
const content = extractTextContent(readableHtml);
|
|
1415
1569
|
const rawSnapshot2 = session.getSnapshot();
|
|
1416
1570
|
const rawDiff2 = hasDiff2 ? session.getDiff() : void 0;
|
|
1417
|
-
const
|
|
1418
|
-
const
|
|
1571
|
+
const scrollContext2 = session.getScrollContext();
|
|
1572
|
+
const win2 = computeVisibleWindow(rawSnapshot2.canvas.viewport, scrollContext2);
|
|
1573
|
+
const scrollable2 = computeScrollable(rawSnapshot2.canvas.viewport, scrollContext2);
|
|
1574
|
+
const viewportFiltered2 = filterObjectsByViewport(rawSnapshot2.objects, win2);
|
|
1575
|
+
const filteredObjects2 = filterObjectsByDetailLevel(viewportFiltered2, detailLevel);
|
|
1576
|
+
const fullSnapshot2 = { ...rawSnapshot2, objects: filteredObjects2 };
|
|
1577
|
+
const fullDiff2 = rawSnapshot2 && rawDiff2 ? filterDiffByViewport(rawDiff2, rawSnapshot2, session.getPreviousSnapshot(), win2) : rawDiff2;
|
|
1419
1578
|
const data2 = {
|
|
1420
1579
|
url: args.url,
|
|
1421
1580
|
mode: "render",
|
|
1422
1581
|
content,
|
|
1423
|
-
vslDocument,
|
|
1582
|
+
vslDocument: rawSnapshot2,
|
|
1424
1583
|
snapshot: fullSnapshot2,
|
|
1425
1584
|
diff: fullDiff2,
|
|
1426
1585
|
hasDiff: hasDiff2,
|
|
@@ -1430,7 +1589,8 @@ async function handleReadPage(args, browser, session, _config) {
|
|
|
1430
1589
|
isSpa,
|
|
1431
1590
|
readableApplied: readable,
|
|
1432
1591
|
detail_level: detailLevel,
|
|
1433
|
-
...computeVslMetrics(fullSnapshot2)
|
|
1592
|
+
...computeVslMetrics(fullSnapshot2),
|
|
1593
|
+
scrollable: scrollable2
|
|
1434
1594
|
}
|
|
1435
1595
|
};
|
|
1436
1596
|
return {
|
|
@@ -1447,8 +1607,13 @@ async function handleReadPage(args, browser, session, _config) {
|
|
|
1447
1607
|
const hasDiff = hadPreviousSnapshot;
|
|
1448
1608
|
const rawSnapshot = session.getSnapshot();
|
|
1449
1609
|
const rawDiff = hasDiff ? session.getDiff() : void 0;
|
|
1450
|
-
const
|
|
1451
|
-
const
|
|
1610
|
+
const scrollContext = session.getScrollContext();
|
|
1611
|
+
const win = computeVisibleWindow(rawSnapshot.canvas.viewport, scrollContext);
|
|
1612
|
+
const scrollable = computeScrollable(rawSnapshot.canvas.viewport, scrollContext);
|
|
1613
|
+
const viewportFiltered = filterObjectsByViewport(rawSnapshot.objects, win);
|
|
1614
|
+
const filteredObjects = filterObjectsByDetailLevel(viewportFiltered, detailLevel);
|
|
1615
|
+
const fullSnapshot = { ...rawSnapshot, objects: filteredObjects };
|
|
1616
|
+
const fullDiff = rawSnapshot && rawDiff ? filterDiffByViewport(rawDiff, rawSnapshot, session.getPreviousSnapshot(), win) : rawDiff;
|
|
1452
1617
|
const data = {
|
|
1453
1618
|
url: args.url,
|
|
1454
1619
|
mode: "http",
|
|
@@ -1463,7 +1628,8 @@ async function handleReadPage(args, browser, session, _config) {
|
|
|
1463
1628
|
isSpa: httpResult.isSpa,
|
|
1464
1629
|
readableApplied: httpResult.readableApplied,
|
|
1465
1630
|
detail_level: detailLevel,
|
|
1466
|
-
...computeVslMetrics(fullSnapshot)
|
|
1631
|
+
...computeVslMetrics(fullSnapshot),
|
|
1632
|
+
scrollable
|
|
1467
1633
|
}
|
|
1468
1634
|
};
|
|
1469
1635
|
return {
|
|
@@ -1583,31 +1749,6 @@ function computeVslMetrics(snapshot) {
|
|
|
1583
1749
|
}
|
|
1584
1750
|
}
|
|
1585
1751
|
|
|
1586
|
-
// src/tools/getFullJson.ts
|
|
1587
|
-
async function handleGetFullJson(_args, session) {
|
|
1588
|
-
const startTime = Date.now();
|
|
1589
|
-
try {
|
|
1590
|
-
if (!session.hasSnapshot()) {
|
|
1591
|
-
return {
|
|
1592
|
-
status: "error",
|
|
1593
|
-
error: "No VSL snapshot available",
|
|
1594
|
-
hint: "Call vsl_get_snapshot first to capture the current page state."
|
|
1595
|
-
};
|
|
1596
|
-
}
|
|
1597
|
-
const snapshot = session.getSnapshot();
|
|
1598
|
-
return {
|
|
1599
|
-
status: "success",
|
|
1600
|
-
data: snapshot,
|
|
1601
|
-
metadata: computeToolMetrics(snapshot, startTime)
|
|
1602
|
-
};
|
|
1603
|
-
} catch (error) {
|
|
1604
|
-
return {
|
|
1605
|
-
status: "error",
|
|
1606
|
-
error: `vsl_get_full_json failed: ${error instanceof Error ? error.message : String(error)}`
|
|
1607
|
-
};
|
|
1608
|
-
}
|
|
1609
|
-
}
|
|
1610
|
-
|
|
1611
1752
|
// src/tools/getTextBlock.ts
|
|
1612
1753
|
async function handleGetTextBlock(args, session) {
|
|
1613
1754
|
const startTime = Date.now();
|
|
@@ -1655,147 +1796,6 @@ async function handleGetTextBlock(args, session) {
|
|
|
1655
1796
|
}
|
|
1656
1797
|
}
|
|
1657
1798
|
|
|
1658
|
-
// src/tools/download.ts
|
|
1659
|
-
import path from "path";
|
|
1660
|
-
async function handleDownload(args, browser, session) {
|
|
1661
|
-
try {
|
|
1662
|
-
if (!args.target_id && !args.value) {
|
|
1663
|
-
return {
|
|
1664
|
-
status: "error",
|
|
1665
|
-
error: "Either target_id (element to click) or value (URL to download) is required"
|
|
1666
|
-
};
|
|
1667
|
-
}
|
|
1668
|
-
if (args.target_id !== void 0 && typeof args.target_id !== "string") {
|
|
1669
|
-
return {
|
|
1670
|
-
status: "error",
|
|
1671
|
-
error: "target_id must be a string"
|
|
1672
|
-
};
|
|
1673
|
-
}
|
|
1674
|
-
if (args.value !== void 0 && typeof args.value !== "string") {
|
|
1675
|
-
return {
|
|
1676
|
-
status: "error",
|
|
1677
|
-
error: "value must be a string"
|
|
1678
|
-
};
|
|
1679
|
-
}
|
|
1680
|
-
if (args.timeout !== void 0 && (typeof args.timeout !== "number" || args.timeout <= 0)) {
|
|
1681
|
-
return {
|
|
1682
|
-
status: "error",
|
|
1683
|
-
error: "timeout must be a positive number (milliseconds)"
|
|
1684
|
-
};
|
|
1685
|
-
}
|
|
1686
|
-
if (args.save_path !== void 0 && typeof args.save_path !== "string") {
|
|
1687
|
-
return {
|
|
1688
|
-
status: "error",
|
|
1689
|
-
error: "save_path must be a string"
|
|
1690
|
-
};
|
|
1691
|
-
}
|
|
1692
|
-
if (args.target_id && !session.hasSnapshot()) {
|
|
1693
|
-
return {
|
|
1694
|
-
status: "error",
|
|
1695
|
-
error: "No snapshot available. Call vsl_get_snapshot first."
|
|
1696
|
-
};
|
|
1697
|
-
}
|
|
1698
|
-
const isAvailable = await browser.isAvailable();
|
|
1699
|
-
if (!isAvailable) {
|
|
1700
|
-
return {
|
|
1701
|
-
status: "error",
|
|
1702
|
-
error: "Playwright is not installed. Install it with: npm install playwright"
|
|
1703
|
-
};
|
|
1704
|
-
}
|
|
1705
|
-
if (session.hasSnapshot()) {
|
|
1706
|
-
const snapshot = session.getSnapshot();
|
|
1707
|
-
const snapshotUrl = snapshot.canvas.url;
|
|
1708
|
-
if (snapshotUrl) {
|
|
1709
|
-
const currentUrl = await browser.evaluate(() => window.location.href);
|
|
1710
|
-
if (currentUrl !== snapshotUrl) {
|
|
1711
|
-
await browser.navigate(snapshotUrl);
|
|
1712
|
-
}
|
|
1713
|
-
}
|
|
1714
|
-
}
|
|
1715
|
-
let downloadUrl;
|
|
1716
|
-
if (args.value) {
|
|
1717
|
-
downloadUrl = args.value;
|
|
1718
|
-
await browser.evaluate((url) => {
|
|
1719
|
-
const a = document.createElement("a");
|
|
1720
|
-
a.href = url;
|
|
1721
|
-
a.download = "";
|
|
1722
|
-
document.body.appendChild(a);
|
|
1723
|
-
a.click();
|
|
1724
|
-
document.body.removeChild(a);
|
|
1725
|
-
}, args.value);
|
|
1726
|
-
} else if (args.target_id) {
|
|
1727
|
-
const selector = `[data-vsl-id="${args.target_id}"], #${args.target_id}, .${args.target_id}`;
|
|
1728
|
-
downloadUrl = await browser.evaluate((sel) => {
|
|
1729
|
-
const el = document.querySelector(sel);
|
|
1730
|
-
if (el) {
|
|
1731
|
-
let url = "";
|
|
1732
|
-
if (el instanceof HTMLAnchorElement && el.href) {
|
|
1733
|
-
url = el.href;
|
|
1734
|
-
}
|
|
1735
|
-
el.click();
|
|
1736
|
-
return url;
|
|
1737
|
-
}
|
|
1738
|
-
return "";
|
|
1739
|
-
}, selector);
|
|
1740
|
-
if (!downloadUrl) {
|
|
1741
|
-
downloadUrl = await browser.evaluate(() => window.location.href);
|
|
1742
|
-
}
|
|
1743
|
-
} else {
|
|
1744
|
-
return {
|
|
1745
|
-
status: "error",
|
|
1746
|
-
error: "Invalid arguments: provide either target_id or value"
|
|
1747
|
-
};
|
|
1748
|
-
}
|
|
1749
|
-
const downloads = browser.getDownloads();
|
|
1750
|
-
if (downloads.length === 0) {
|
|
1751
|
-
return {
|
|
1752
|
-
status: "error",
|
|
1753
|
-
error: "Download was not initiated. Check if the element triggers a file download."
|
|
1754
|
-
};
|
|
1755
|
-
}
|
|
1756
|
-
const latestDownload = downloads[downloads.length - 1];
|
|
1757
|
-
if (!latestDownload) {
|
|
1758
|
-
return {
|
|
1759
|
-
status: "error",
|
|
1760
|
-
error: "No active downloads found after triggering download."
|
|
1761
|
-
};
|
|
1762
|
-
}
|
|
1763
|
-
const downloadId = latestDownload.downloadId;
|
|
1764
|
-
const timeout = args.timeout;
|
|
1765
|
-
const result = await browser.waitForDownload(downloadId, timeout);
|
|
1766
|
-
if (args.save_path && result.status === "completed") {
|
|
1767
|
-
const isAbsolute = args.save_path.startsWith("/");
|
|
1768
|
-
if (!isAbsolute) {
|
|
1769
|
-
const resolvedBase = path.resolve((await import("os")).homedir(), ".vsl", "downloads");
|
|
1770
|
-
const resolvedSave = path.resolve(resolvedBase, args.save_path);
|
|
1771
|
-
if (!resolvedSave.startsWith(resolvedBase + path.sep) && resolvedSave !== resolvedBase) {
|
|
1772
|
-
return {
|
|
1773
|
-
status: "error",
|
|
1774
|
-
error: `Path traversal detected: save_path '${args.save_path}' escapes downloads directory`
|
|
1775
|
-
};
|
|
1776
|
-
}
|
|
1777
|
-
}
|
|
1778
|
-
await browser.saveDownload(downloadId, args.save_path);
|
|
1779
|
-
result.path = args.save_path;
|
|
1780
|
-
}
|
|
1781
|
-
return {
|
|
1782
|
-
status: "success",
|
|
1783
|
-
data: {
|
|
1784
|
-
downloadId: result.downloadId,
|
|
1785
|
-
filename: result.filename,
|
|
1786
|
-
url: result.url,
|
|
1787
|
-
status: result.status,
|
|
1788
|
-
path: result.path
|
|
1789
|
-
}
|
|
1790
|
-
};
|
|
1791
|
-
} catch (error) {
|
|
1792
|
-
return {
|
|
1793
|
-
status: "error",
|
|
1794
|
-
error: `vsl_download failed: ${error instanceof Error ? error.message : String(error)}`
|
|
1795
|
-
};
|
|
1796
|
-
}
|
|
1797
|
-
}
|
|
1798
|
-
|
|
1799
1799
|
// src/tools/index.ts
|
|
1800
1800
|
var VSL_TOOLS = [
|
|
1801
1801
|
{
|
|
@@ -1816,18 +1816,14 @@ var VSL_TOOLS = [
|
|
|
1816
1816
|
ttl: {
|
|
1817
1817
|
type: "number",
|
|
1818
1818
|
description: "TTL \u043A\u044D\u0448\u0430 \u0432 \u043C\u0438\u043B\u043B\u0438\u0441\u0435\u043A\u0443\u043D\u0434\u0430\u0445 (default: 5000 = 5s). \u0423\u0441\u0442\u0430\u043D\u043E\u0432\u0438\u0442\u0435 0 \u0434\u043B\u044F \u043E\u0442\u043A\u043B\u044E\u0447\u0435\u043D\u0438\u044F \u043A\u044D\u0448\u0438\u0440\u043E\u0432\u0430\u043D\u0438\u044F."
|
|
1819
|
+
},
|
|
1820
|
+
full: {
|
|
1821
|
+
type: "boolean",
|
|
1822
|
+
description: "\u041F\u043E\u043B\u043D\u044B\u0439 \u0440\u0435\u0436\u0438\u043C: \u0432\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0432\u0435\u0441\u044C \u0434\u043E\u043A\u0443\u043C\u0435\u043D\u0442 \u0431\u0435\u0437 \u0444\u0438\u043B\u044C\u0442\u0440\u043E\u0432 (\u0437\u0430\u043C\u0435\u043D\u0430 \u0443\u0434\u0430\u043B\u0451\u043D\u043D\u043E\u0433\u043E \u0442\u0443\u043B\u0430 \u043F\u043E\u043B\u043D\u043E\u0433\u043E \u0441\u043D\u0430\u043F\u0448\u043E\u0442\u0430)"
|
|
1819
1823
|
}
|
|
1820
1824
|
}
|
|
1821
1825
|
}
|
|
1822
1826
|
},
|
|
1823
|
-
{
|
|
1824
|
-
name: "vsl_get_diff",
|
|
1825
|
-
description: "\u041F\u043E\u043B\u0443\u0447\u0438\u0442\u044C \u0442\u043E\u043B\u044C\u043A\u043E \u0438\u0437\u043C\u0435\u043D\u0435\u043D\u0438\u044F \u0441 \u043C\u043E\u043C\u0435\u043D\u0442\u0430 \u043F\u043E\u0441\u043B\u0435\u0434\u043D\u0435\u0433\u043E snapshot. \u0412\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 Diff JSON \u0441 \u0441\u0435\u043A\u0446\u0438\u044F\u043C\u0438 added (\u043D\u043E\u0432\u044B\u0435 \u043E\u0431\u044A\u0435\u043A\u0442\u044B), modified (\u0438\u0437\u043C\u0435\u043D\u0451\u043D\u043D\u044B\u0435), removed (\u0443\u0434\u0430\u043B\u0451\u043D\u043D\u044B\u0435). \u041F\u0440\u0438\u043C\u0435\u0440: { changes:{ added:[{id:btn_3,type:button,text:\u041E\u0442\u043F\u0440\u0430\u0432\u0438\u0442\u044C,bbox:[300,400,100,30]}], modified:[{id:btn_1,changes:{text:[\u0412\u043E\u0439\u0442\u0438,\u0410\u0432\u0442\u043E\u0440\u0438\u0437\u0430\u0446\u0438\u044F]}}], removed:[{id:inp_2}] } }. \u0418\u0441\u043F\u043E\u043B\u044C\u0437\u0443\u0439\u0442\u0435 \u0434\u043B\u044F \u043E\u0442\u0441\u043B\u0435\u0436\u0438\u0432\u0430\u043D\u0438\u044F \u0438\u0437\u043C\u0435\u043D\u0435\u043D\u0438\u0439 \u043D\u0430 \u0441\u0442\u0440\u0430\u043D\u0438\u0446\u0435 \u043F\u043E\u0441\u043B\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 (\u043A\u043B\u0438\u043A, \u043D\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u044F, \u0444\u043E\u0440\u043C\u0430).",
|
|
1826
|
-
inputSchema: {
|
|
1827
|
-
type: "object",
|
|
1828
|
-
properties: {}
|
|
1829
|
-
}
|
|
1830
|
-
},
|
|
1831
1827
|
{
|
|
1832
1828
|
name: "vsl_execute_action",
|
|
1833
1829
|
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 \u043D\u0430 \u043A\u043B\u0430\u0432\u0438\u0430\u0442\u0443\u0440\u0435, \u0442\u0440\u0435\u0431\u0443\u0435\u0442 value \u2014 \u043D\u0430\u0437\u0432\u0430\u043D\u0438\u0435 \u043A\u043B\u0430\u0432\u0438\u0448\u0438, \u043D\u0430\u043F\u0440\u0438\u043C\u0435\u0440 "Enter", "Tab", "Escape", "ArrowDown", "ArrowUp", "Space", "Backspace". \u0418\u0441\u043F\u043E\u043B\u044C\u0437\u0443\u0435\u0442\u0441\u044F \u0434\u043B\u044F \u043E\u0442\u043F\u0440\u0430\u0432\u043A\u0438 \u0444\u043E\u0440\u043C \u0447\u0435\u0440\u0435\u0437 Enter, \u043D\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0438 \u0447\u0435\u0440\u0435\u0437 Tab, \u0437\u0430\u043A\u0440\u044B\u0442\u0438\u044F \u043C\u043E\u0434\u0430\u043B\u043E\u043A \u0447\u0435\u0440\u0435\u0437 Escape \u0438 \u0442.\u0434.), 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:press, target_id:inp_1, value:Enter} \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.',
|
|
@@ -1849,6 +1845,14 @@ var VSL_TOOLS = [
|
|
|
1849
1845
|
return_state: {
|
|
1850
1846
|
type: "boolean",
|
|
1851
1847
|
description: "\u0415\u0441\u043B\u0438 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. \u041F\u043E\u043B\u0435\u0437\u043D\u043E \u0434\u043B\u044F \u043E\u0442\u0441\u043B\u0435\u0436\u0438\u0432\u0430\u043D\u0438\u044F \u0438\u0437\u043C\u0435\u043D\u0435\u043D\u0438\u0439 DOM \u0431\u0435\u0437 \u0434\u043E\u043F\u043E\u043B\u043D\u0438\u0442\u0435\u043B\u044C\u043D\u043E\u0433\u043E \u0432\u044B\u0437\u043E\u0432\u0430 vsl_get_diff. Default: true \u2014 \u0432\u0441\u0435\u0433\u0434\u0430 \u0432\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044C \u0441\u043E\u0441\u0442\u043E\u044F\u043D\u0438\u0435 \u0434\u043B\u044F \u044D\u043A\u043E\u043D\u043E\u043C\u0438\u0438 \u0445\u043E\u0434\u043E\u0432 \u0430\u0433\u0435\u043D\u0442\u0430. \u0423\u0441\u0442\u0430\u043D\u043E\u0432\u0438\u0442\u0435 false \u0434\u043B\u044F \u043E\u0442\u043A\u043B\u044E\u0447\u0435\u043D\u0438\u044F."
|
|
1848
|
+
},
|
|
1849
|
+
timeout: {
|
|
1850
|
+
type: "number",
|
|
1851
|
+
description: "\u0422\u0430\u0439\u043C\u0430\u0443\u0442 \u043E\u0436\u0438\u0434\u0430\u043D\u0438\u044F \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043D\u0438\u044F \u0441\u043A\u0430\u0447\u0438\u0432\u0430\u043D\u0438\u044F \u0432 \u043C\u0441 (\u0442\u043E\u043B\u044C\u043A\u043E \u0434\u043B\u044F \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044F download)"
|
|
1852
|
+
},
|
|
1853
|
+
save_path: {
|
|
1854
|
+
type: "string",
|
|
1855
|
+
description: "\u041F\u0443\u0442\u044C \u0434\u043B\u044F \u0441\u043E\u0445\u0440\u0430\u043D\u0435\u043D\u0438\u044F \u0441\u043A\u0430\u0447\u0430\u043D\u043D\u043E\u0433\u043E \u0444\u0430\u0439\u043B\u0430 (\u0442\u043E\u043B\u044C\u043A\u043E \u0434\u043B\u044F \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044F download)"
|
|
1852
1856
|
}
|
|
1853
1857
|
},
|
|
1854
1858
|
required: ["action", "target_id"]
|
|
@@ -1912,14 +1916,6 @@ var VSL_TOOLS = [
|
|
|
1912
1916
|
required: ["url"]
|
|
1913
1917
|
}
|
|
1914
1918
|
},
|
|
1915
|
-
{
|
|
1916
|
-
name: "vsl_get_full_json",
|
|
1917
|
-
description: "\u041F\u043E\u043B\u0443\u0447\u0438\u0442\u044C \u043F\u043E\u043B\u043D\u044B\u0439 VSL JSON \u0442\u0435\u043A\u0443\u0449\u0435\u0439 \u0441\u0442\u0440\u0430\u043D\u0438\u0446\u044B, \u043C\u0438\u043D\u0443\u044F diff-first \u043B\u043E\u0433\u0438\u043A\u0443. \u0418\u0441\u043F\u043E\u043B\u044C\u0437\u0443\u0439\u0442\u0435 \u043A\u043E\u0433\u0434\u0430: (1) \u0438\u0441\u0442\u043E\u0440\u0438\u044F \u0430\u0433\u0435\u043D\u0442\u0430 \u043E\u0431\u0440\u0435\u0437\u0430\u043B\u0430\u0441\u044C \u0438 \u0432\u044B \u043F\u043E\u0442\u0435\u0440\u044F\u043B\u0438 \u043A\u043E\u043D\u0442\u0435\u043A\u0441\u0442, (2) \u043D\u0443\u0436\u043D\u043E \u0443\u0432\u0438\u0434\u0435\u0442\u044C \u043F\u043E\u043B\u043D\u0443\u044E \u043A\u0430\u0440\u0442\u0438\u043D\u0443 \u0441\u0442\u0440\u0430\u043D\u0438\u0446\u044B, (3) \u0438\u043D\u043A\u0440\u0435\u043C\u0435\u043D\u0442\u0430\u043B\u044C\u043D\u044B\u0435 \u0434\u0438\u0444\u0444\u044B \u043D\u0435 \u0434\u0430\u044E\u0442 \u0434\u043E\u0441\u0442\u0430\u0442\u043E\u0447\u043D\u043E \u0438\u043D\u0444\u043E\u0440\u043C\u0430\u0446\u0438\u0438. \u041F\u0440\u0438\u043C\u0435\u0440: {}. \u0412\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043F\u043E\u043B\u043D\u044B\u0439 VSL Document \u0441 viewport \u0438 objects.",
|
|
1918
|
-
inputSchema: {
|
|
1919
|
-
type: "object",
|
|
1920
|
-
properties: {}
|
|
1921
|
-
}
|
|
1922
|
-
},
|
|
1923
1919
|
{
|
|
1924
1920
|
name: "vsl_get_text_block",
|
|
1925
1921
|
description: '\u041F\u043E\u043B\u0443\u0447\u0438\u0442\u044C \u043F\u043E\u043B\u043D\u044B\u0439 \u0442\u0435\u043A\u0441\u0442 \u043F\u043E txt_ref \u0438\u0437 lazy text loading (M1.7). \u041A\u043E\u0433\u0434\u0430 \u0442\u0435\u043A\u0441\u0442 \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u0430 > 200 \u0441\u0438\u043C\u0432\u043E\u043B\u043E\u0432, \u0432 VSL JSON \u0445\u0440\u0430\u043D\u0438\u0442\u0441\u044F \u0442\u043E\u043B\u044C\u043A\u043E txt_preview (\u043F\u0435\u0440\u0432\u044B\u0435 ~50 \u0441\u0438\u043C\u0432\u043E\u043B\u043E\u0432) \u0438 txt_ref (\u043D\u0430\u043F\u0440\u0438\u043C\u0435\u0440, tb_001). \u0418\u0441\u043F\u043E\u043B\u044C\u0437\u0443\u0439\u0442\u0435 \u044D\u0442\u043E\u0442 tool \u0434\u043B\u044F \u043F\u043E\u043B\u0443\u0447\u0435\u043D\u0438\u044F \u043F\u043E\u043B\u043D\u043E\u0433\u043E \u0442\u0435\u043A\u0441\u0442\u0430. \u041F\u0440\u0438\u043C\u0435\u0440: {block_id: "tb_001"}. \u0412\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 {block_id, text} \u0441 \u043F\u043E\u043B\u043D\u044B\u043C \u0441\u043E\u0434\u0435\u0440\u0436\u0438\u043C\u044B\u043C.',
|
|
@@ -1933,31 +1929,6 @@ var VSL_TOOLS = [
|
|
|
1933
1929
|
},
|
|
1934
1930
|
required: ["block_id"]
|
|
1935
1931
|
}
|
|
1936
|
-
},
|
|
1937
|
-
{
|
|
1938
|
-
name: "vsl_download",
|
|
1939
|
-
description: '\u0423\u043F\u0440\u0430\u0432\u043B\u0435\u043D\u0438\u0435 \u0441\u043A\u0430\u0447\u0438\u0432\u0430\u043D\u0438\u0435\u043C \u0444\u0430\u0439\u043B\u043E\u0432 \u0447\u0435\u0440\u0435\u0437 Playwright BrowserContext. \u0414\u0432\u0430 \u0440\u0435\u0436\u0438\u043C\u0430: (1) target_id \u2014 \u043A\u043B\u0438\u043A \u043F\u043E \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u0443 (\u043A\u043D\u043E\u043F\u043A\u0430/\u0441\u0441\u044B\u043B\u043A\u0430 \u0434\u043B\u044F \u0441\u043A\u0430\u0447\u0438\u0432\u0430\u043D\u0438\u044F), \u0438\u043D\u0438\u0446\u0438\u0438\u0440\u0443\u0435\u0442 download \u0447\u0435\u0440\u0435\u0437 Playwright; (2) value \u2014 \u043F\u0440\u044F\u043C\u043E\u0435 \u0441\u043A\u0430\u0447\u0438\u0432\u0430\u043D\u0438\u0435 \u043F\u043E URL (\u0441\u043E\u0437\u0434\u0430\u0451\u0442 <a download> \u0438 \u043A\u043B\u0438\u043A\u0430\u0435\u0442). \u0412\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 downloadId, filename, url, status (completed/failed/cancelled), path. \u041F\u0440\u0438\u043C\u0435\u0440\u044B: {target_id: btn_download} \u0438\u043B\u0438 {value: "https://example.com/file.pdf"}. \u041E\u043F\u0446\u0438\u043E\u043D\u0430\u043B\u044C\u043D\u043E: timeout (\u043C\u0441), save_path (\u043F\u0443\u0442\u044C \u0434\u043B\u044F \u0441\u043E\u0445\u0440\u0430\u043D\u0435\u043D\u0438\u044F).',
|
|
1940
|
-
inputSchema: {
|
|
1941
|
-
type: "object",
|
|
1942
|
-
properties: {
|
|
1943
|
-
target_id: {
|
|
1944
|
-
type: "string",
|
|
1945
|
-
description: "ID \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u0430 \u0434\u043B\u044F \u043A\u043B\u0438\u043A\u0430 (\u043A\u043D\u043E\u043F\u043A\u0430/\u0441\u0441\u044B\u043B\u043A\u0430 \u0434\u043B\u044F \u0441\u043A\u0430\u0447\u0438\u0432\u0430\u043D\u0438\u044F)"
|
|
1946
|
-
},
|
|
1947
|
-
value: {
|
|
1948
|
-
type: "string",
|
|
1949
|
-
description: "URL \u0434\u043B\u044F \u043F\u0440\u044F\u043C\u043E\u0433\u043E \u0441\u043A\u0430\u0447\u0438\u0432\u0430\u043D\u0438\u044F"
|
|
1950
|
-
},
|
|
1951
|
-
timeout: {
|
|
1952
|
-
type: "number",
|
|
1953
|
-
description: "\u0422\u0430\u0439\u043C\u0430\u0443\u0442 \u043E\u0436\u0438\u0434\u0430\u043D\u0438\u044F \u0437\u0430\u0433\u0440\u0443\u0437\u043A\u0438 \u0432 \u043C\u0441 (\u043F\u043E \u0443\u043C\u043E\u043B\u0447\u0430\u043D\u0438\u044E \u0438\u0437 config)"
|
|
1954
|
-
},
|
|
1955
|
-
save_path: {
|
|
1956
|
-
type: "string",
|
|
1957
|
-
description: "\u041F\u0443\u0442\u044C \u0434\u043B\u044F \u0441\u043E\u0445\u0440\u0430\u043D\u0435\u043D\u0438\u044F \u0444\u0430\u0439\u043B\u0430 (\u043E\u043F\u0446\u0438\u043E\u043D\u0430\u043B\u044C\u043D\u043E)"
|
|
1958
|
-
}
|
|
1959
|
-
}
|
|
1960
|
-
}
|
|
1961
1932
|
}
|
|
1962
1933
|
];
|
|
1963
1934
|
function registerTools(server, config, sessionManager) {
|
|
@@ -1976,9 +1947,6 @@ function registerTools(server, config, sessionManager) {
|
|
|
1976
1947
|
case "vsl_get_snapshot":
|
|
1977
1948
|
result = await handleGetSnapshot(args, browser, session, config);
|
|
1978
1949
|
break;
|
|
1979
|
-
case "vsl_get_diff":
|
|
1980
|
-
result = await handleGetDiff(session);
|
|
1981
|
-
break;
|
|
1982
1950
|
case "vsl_execute_action":
|
|
1983
1951
|
result = await handleExecuteAction(args, browser, session);
|
|
1984
1952
|
break;
|
|
@@ -1994,15 +1962,9 @@ function registerTools(server, config, sessionManager) {
|
|
|
1994
1962
|
case "vsl_read_page":
|
|
1995
1963
|
result = await handleReadPage(args, browser, session, config);
|
|
1996
1964
|
break;
|
|
1997
|
-
case "vsl_get_full_json":
|
|
1998
|
-
result = await handleGetFullJson(args, session);
|
|
1999
|
-
break;
|
|
2000
1965
|
case "vsl_get_text_block":
|
|
2001
1966
|
result = await handleGetTextBlock(args, session);
|
|
2002
1967
|
break;
|
|
2003
|
-
case "vsl_download":
|
|
2004
|
-
result = await handleDownload(args, browser, session);
|
|
2005
|
-
break;
|
|
2006
1968
|
default:
|
|
2007
1969
|
return {
|
|
2008
1970
|
content: [
|
|
@@ -2157,7 +2119,7 @@ function registerResources(server, _config, sessionManager) {
|
|
|
2157
2119
|
}
|
|
2158
2120
|
|
|
2159
2121
|
// src/browser/manager.ts
|
|
2160
|
-
import
|
|
2122
|
+
import path from "path";
|
|
2161
2123
|
import os from "os";
|
|
2162
2124
|
var BrowserManager = class {
|
|
2163
2125
|
browser = null;
|
|
@@ -2296,13 +2258,13 @@ var BrowserManager = class {
|
|
|
2296
2258
|
path: null
|
|
2297
2259
|
};
|
|
2298
2260
|
}
|
|
2299
|
-
const
|
|
2261
|
+
const path2 = await download.path();
|
|
2300
2262
|
return {
|
|
2301
2263
|
downloadId,
|
|
2302
2264
|
filename: download.suggestedFilename(),
|
|
2303
2265
|
url: download.url(),
|
|
2304
2266
|
status: "completed",
|
|
2305
|
-
path:
|
|
2267
|
+
path: path2
|
|
2306
2268
|
};
|
|
2307
2269
|
} catch {
|
|
2308
2270
|
return {
|
|
@@ -2339,9 +2301,9 @@ var BrowserManager = class {
|
|
|
2339
2301
|
await download.saveAs(savePath);
|
|
2340
2302
|
} else {
|
|
2341
2303
|
const downloadsPath = this.config.downloadsPath ?? os.tmpdir();
|
|
2342
|
-
const resolvedBase =
|
|
2343
|
-
const resolvedSave =
|
|
2344
|
-
if (!resolvedSave.startsWith(resolvedBase +
|
|
2304
|
+
const resolvedBase = path.resolve(downloadsPath.replace(/^~/, os.homedir()));
|
|
2305
|
+
const resolvedSave = path.resolve(resolvedBase, savePath);
|
|
2306
|
+
if (!resolvedSave.startsWith(resolvedBase + path.sep) && resolvedSave !== resolvedBase) {
|
|
2345
2307
|
throw new Error(`Path traversal detected: save_path '${savePath}' escapes downloads directory '${resolvedBase}'`);
|
|
2346
2308
|
}
|
|
2347
2309
|
await download.saveAs(resolvedSave);
|
|
@@ -2381,13 +2343,13 @@ var BrowserManager = class {
|
|
|
2381
2343
|
}
|
|
2382
2344
|
const resolvedPaths = [];
|
|
2383
2345
|
for (const filePath of filePaths) {
|
|
2384
|
-
const isAbsolute =
|
|
2346
|
+
const isAbsolute = path.isAbsolute(filePath);
|
|
2385
2347
|
if (isAbsolute) {
|
|
2386
2348
|
resolvedPaths.push(filePath);
|
|
2387
2349
|
} else {
|
|
2388
|
-
const resolved =
|
|
2389
|
-
const cwd =
|
|
2390
|
-
if (!resolved.startsWith(cwd +
|
|
2350
|
+
const resolved = path.resolve(process.cwd(), filePath);
|
|
2351
|
+
const cwd = path.resolve(process.cwd());
|
|
2352
|
+
if (!resolved.startsWith(cwd + path.sep) && resolved !== cwd) {
|
|
2391
2353
|
throw new Error(`Path traversal detected: file path '${filePath}' resolves outside working directory '${cwd}'`);
|
|
2392
2354
|
}
|
|
2393
2355
|
resolvedPaths.push(resolved);
|
|
@@ -2437,6 +2399,8 @@ var ServerSession = class {
|
|
|
2437
2399
|
previousDocument = null;
|
|
2438
2400
|
version = 0;
|
|
2439
2401
|
onSnapshotChange = null;
|
|
2402
|
+
/** Метаданные скролла последнего снапшота (единый пайплайн отдачи, АС[3]). */
|
|
2403
|
+
scrollContext = null;
|
|
2440
2404
|
/**
|
|
2441
2405
|
* Регистрирует callback для уведомлений об изменении snapshot.
|
|
2442
2406
|
* Вызывается при каждом вызове setSnapshot().
|
|
@@ -2454,6 +2418,7 @@ var ServerSession = class {
|
|
|
2454
2418
|
}
|
|
2455
2419
|
this.currentDocument = doc;
|
|
2456
2420
|
this.version += 1;
|
|
2421
|
+
this.scrollContext = null;
|
|
2457
2422
|
if (this.onSnapshotChange) {
|
|
2458
2423
|
this.onSnapshotChange();
|
|
2459
2424
|
}
|
|
@@ -2476,6 +2441,7 @@ var ServerSession = class {
|
|
|
2476
2441
|
}
|
|
2477
2442
|
this.currentDocument = doc;
|
|
2478
2443
|
this.version += 1;
|
|
2444
|
+
this.scrollContext = input.scroll ? { ...input.scroll } : null;
|
|
2479
2445
|
if (this.onSnapshotChange) {
|
|
2480
2446
|
this.onSnapshotChange();
|
|
2481
2447
|
}
|
|
@@ -2497,6 +2463,13 @@ var ServerSession = class {
|
|
|
2497
2463
|
}
|
|
2498
2464
|
return this.currentDocument;
|
|
2499
2465
|
}
|
|
2466
|
+
/**
|
|
2467
|
+
* Возвращает предыдущий полный документ (для вьюпорт-фильтра диффа:
|
|
2468
|
+
* видимость removed-объектов определяется по prev-документу).
|
|
2469
|
+
*/
|
|
2470
|
+
getPreviousSnapshot() {
|
|
2471
|
+
return this.previousDocument;
|
|
2472
|
+
}
|
|
2500
2473
|
/**
|
|
2501
2474
|
* Проверяет, есть ли текущий snapshot.
|
|
2502
2475
|
*/
|
|
@@ -2524,6 +2497,7 @@ var ServerSession = class {
|
|
|
2524
2497
|
this.currentDocument = null;
|
|
2525
2498
|
this.previousDocument = null;
|
|
2526
2499
|
this.version = 0;
|
|
2500
|
+
this.scrollContext = null;
|
|
2527
2501
|
}
|
|
2528
2502
|
/**
|
|
2529
2503
|
* Возвращает текущую версию snapshot.
|
|
@@ -2531,6 +2505,20 @@ var ServerSession = class {
|
|
|
2531
2505
|
getVersion() {
|
|
2532
2506
|
return this.version;
|
|
2533
2507
|
}
|
|
2508
|
+
/**
|
|
2509
|
+
* Возвращает метаданные скролла последнего снапшота (единый пайплайн отдачи).
|
|
2510
|
+
* Используются для вычисления видимого окна и метаданных scrollable {top, bottom}.
|
|
2511
|
+
*/
|
|
2512
|
+
getScrollContext() {
|
|
2513
|
+
return this.scrollContext;
|
|
2514
|
+
}
|
|
2515
|
+
/**
|
|
2516
|
+
* Устанавливает скролл-контекст явно (для путей, идущих мимо
|
|
2517
|
+
* snapshotFromElements).
|
|
2518
|
+
*/
|
|
2519
|
+
setScrollContext(scroll) {
|
|
2520
|
+
this.scrollContext = scroll;
|
|
2521
|
+
}
|
|
2534
2522
|
};
|
|
2535
2523
|
|
|
2536
2524
|
// src/session/sessionManager.ts
|
|
@@ -2663,7 +2651,7 @@ var SessionManager = class {
|
|
|
2663
2651
|
};
|
|
2664
2652
|
|
|
2665
2653
|
// src/version.ts
|
|
2666
|
-
var VSL_MCP_SERVER_VERSION = "
|
|
2654
|
+
var VSL_MCP_SERVER_VERSION = "1.2.1";
|
|
2667
2655
|
|
|
2668
2656
|
// src/index.ts
|
|
2669
2657
|
async function main() {
|