@thinkingos/vsl-mcp-server 1.3.1 → 1.3.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 CHANGED
@@ -2587,6 +2587,14 @@ import { isVslDiff } from "@thinkingos/vsl-sdk";
2587
2587
  // src/utils/injectVslIds.ts
2588
2588
  function buildInjectionScript() {
2589
2589
  return (objects, semanticMap) => {
2590
+ if (!objects || !Array.isArray(objects)) {
2591
+ console.warn("[VSL] injectVslIds: objects is undefined or not an array, skipping injection");
2592
+ return;
2593
+ }
2594
+ if (!semanticMap || typeof semanticMap !== "object") {
2595
+ console.warn("[VSL] injectVslIds: semanticMap is undefined or not an object, using empty map");
2596
+ semanticMap = {};
2597
+ }
2590
2598
  function parseVslId(id) {
2591
2599
  const match = id.match(/^([a-z][a-z0-9]*(?:_[a-z][a-z0-9]*)*)_(\d+(?:_\d+)*)$/);
2592
2600
  if (!match) return null;
@@ -3071,6 +3079,7 @@ function countObjects(objects) {
3071
3079
  function buildSemanticMap(elements) {
3072
3080
  const map = /* @__PURE__ */ new Map();
3073
3081
  function visit(el) {
3082
+ if (!el || typeof el !== "object") return;
3074
3083
  const elem = el;
3075
3084
  if (!elem.indexPath) return;
3076
3085
  if (elem.role || elem.ariaLabel || elem.ariaLabelledBy) {
@@ -3083,6 +3092,7 @@ function buildSemanticMap(elements) {
3083
3092
  }
3084
3093
  if (elem.children && Array.isArray(elem.children)) {
3085
3094
  for (const child of elem.children) {
3095
+ if (!child || typeof child !== "object") continue;
3086
3096
  visit(child);
3087
3097
  }
3088
3098
  }
@@ -3374,7 +3384,15 @@ async function handleGetSnapshot(args, browser, session, _config, sessionId) {
3374
3384
  const viewport = extraction.viewport;
3375
3385
  const url = args.url || await browser.evaluate(() => window.location.href, sessionId);
3376
3386
  const title = await browser.evaluate(() => document.title, sessionId);
3377
- const semanticMap = buildSemanticMap(extractedElements);
3387
+ let semanticMap = /* @__PURE__ */ new Map();
3388
+ let snapshotWarning;
3389
+ try {
3390
+ semanticMap = buildSemanticMap(extractedElements);
3391
+ } catch (error) {
3392
+ const msg = `buildSemanticMap failed (graceful degradation): ${error instanceof Error ? error.message : String(error)}`;
3393
+ console.error("[VSL]", msg, error);
3394
+ snapshotWarning = msg;
3395
+ }
3378
3396
  const iframeElementsRaw = await browser.evaluate(extractIframesInBrowser, sessionId);
3379
3397
  const iframeElements = Array.isArray(iframeElementsRaw) ? iframeElementsRaw : [];
3380
3398
  if (iframeElements.length > 0) {
@@ -3452,7 +3470,13 @@ async function handleGetSnapshot(args, browser, session, _config, sessionId) {
3452
3470
  await injectVslIdsIntoFrame(browser, iframeInfo.frame, iframeInfo.doc.objects, semanticMap);
3453
3471
  }
3454
3472
  }
3455
- await injectVslIdsIntoDom(browser, currentDoc.objects, semanticMap);
3473
+ try {
3474
+ await injectVslIdsIntoDom(browser, currentDoc.objects, semanticMap, sessionId);
3475
+ } catch (error) {
3476
+ const msg = `injectVslIdsIntoDom failed (graceful degradation): ${error instanceof Error ? error.message : String(error)}`;
3477
+ console.error("[VSL]", msg, error);
3478
+ snapshotWarning = snapshotWarning ? `${snapshotWarning}; ${msg}` : msg;
3479
+ }
3456
3480
  const scrollContext = session.getScrollContext();
3457
3481
  const win = computeVisibleWindow(currentDoc.canvas.viewport, scrollContext);
3458
3482
  const scrollable = computeScrollable(currentDoc.canvas.viewport, scrollContext);
@@ -3478,7 +3502,8 @@ async function handleGetSnapshot(args, browser, session, _config, sessionId) {
3478
3502
  total_objects_count: totalObjectsCount,
3479
3503
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
3480
3504
  execution_time_ms: executionTimeMs,
3481
- scrollable
3505
+ scrollable,
3506
+ ...snapshotWarning ? { warning: snapshotWarning } : {}
3482
3507
  };
3483
3508
  if (ttl > 0) {
3484
3509
  const cacheKey = args.url || "current";
@@ -5022,7 +5047,9 @@ async function handleReadPage(args, browser, session, _config, sessionId) {
5022
5047
  readableApplied: httpResult.readableApplied,
5023
5048
  detail_level: detailLevel,
5024
5049
  ...computeVslMetrics(fullSnapshot),
5025
- scrollable
5050
+ scrollable,
5051
+ id_scheme: "counter",
5052
+ warning: "HTTP path: IDs are sequential counters (e.g., btn_0, inp_1). These IDs are NOT compatible with vsl_execute_action. For interactive actions, use vsl_get_snapshot to get browser DOM IDs."
5026
5053
  }
5027
5054
  };
5028
5055
  return {
@@ -5423,7 +5450,7 @@ var VSL_TOOLS = [
5423
5450
  },
5424
5451
  {
5425
5452
  name: "vsl_get_visual",
5426
- description: "\u041F\u043E\u043B\u0443\u0447\u0438\u0442\u044C visual fragment (\u0441\u043A\u0440\u0438\u043D\u0448\u043E\u0442) \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u0430 \u0432 \u0444\u043E\u0440\u043C\u0430\u0442\u0435 base64 WebP. \u0418\u0441\u043F\u043E\u043B\u044C\u0437\u0443\u0439\u0442\u0435 \u0434\u043B\u044F \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u043E\u0432, \u043A\u043E\u0442\u043E\u0440\u044B\u0435 \u0441\u043B\u043E\u0436\u043D\u043E \u043A\u043B\u0430\u0441\u0441\u0438\u0444\u0438\u0446\u0438\u0440\u043E\u0432\u0430\u0442\u044C \u043F\u043E \u0442\u0435\u043A\u0441\u0442\u0443 (\u0438\u043A\u043E\u043D\u043A\u0438, \u0433\u0440\u0430\u0444\u0438\u043A\u0438, \u043A\u0430\u0441\u0442\u043E\u043C\u043D\u044B\u0435 \u0432\u0438\u0434\u0436\u0435\u0442\u044B). \u0412\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 {mediaType:image/webp, data:base64data}. \u041F\u0440\u0438\u043C\u0435\u0440: {element_id: img_5}. \u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440 auto_refresh=true \u0430\u0432\u0442\u043E\u043C\u0430\u0442\u0438\u0447\u0435\u0441\u043A\u0438 \u043E\u0431\u043D\u043E\u0432\u043B\u044F\u0435\u0442 snapshot \u043F\u0435\u0440\u0435\u0434 \u043F\u043E\u0438\u0441\u043A\u043E\u043C \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u0430.",
5453
+ description: "\u041F\u043E\u043B\u0443\u0447\u0438\u0442\u044C visual fragment (\u0441\u043A\u0440\u0438\u043D\u0448\u043E\u0442) \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u0430 \u0432 \u0444\u043E\u0440\u043C\u0430\u0442\u0435 base64 WebP. \u0418\u0441\u043F\u043E\u043B\u044C\u0437\u0443\u0439\u0442\u0435 \u0434\u043B\u044F \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u043E\u0432, \u043A\u043E\u0442\u043E\u0440\u044B\u0435 \u0441\u043B\u043E\u0436\u043D\u043E \u043A\u043B\u0430\u0441\u0441\u0438\u0444\u0438\u0446\u0438\u0440\u043E\u0432\u0430\u0442\u044C \u043F\u043E \u0442\u0435\u043A\u0441\u0442\u0443 (\u0438\u043A\u043E\u043D\u043A\u0438, \u0433\u0440\u0430\u0444\u0438\u043A\u0438, \u043A\u0430\u0441\u0442\u043E\u043C\u043D\u044B\u0435 \u0432\u0438\u0434\u0436\u0435\u0442\u044B). \u0412\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 {mediaType:image/webp, data:base64data}. \u041F\u0440\u0438\u043C\u0435\u0440: {element_id: img_5}. \u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440 auto_refresh=true \u0430\u0432\u0442\u043E\u043C\u0430\u0442\u0438\u0447\u0435\u0441\u043A\u0438 \u043E\u0431\u043D\u043E\u0432\u043B\u044F\u0435\u0442 snapshot \u043F\u0435\u0440\u0435\u0434 \u043F\u043E\u0438\u0441\u043A\u043E\u043C \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u0430. \u0412\u0410\u0416\u041D\u041E: \u0440\u0430\u0431\u043E\u0442\u0430\u0435\u0442 \u0442\u043E\u043B\u044C\u043A\u043E \u0441 ID \u0438\u0437 vsl_get_snapshot (browser DOM). \u041D\u0415 \u0440\u0430\u0431\u043E\u0442\u0430\u0435\u0442 \u0441 ID \u0438\u0437 vsl_read_page (semantic IDs) \u2014 \u0438\u0441\u043F\u043E\u043B\u044C\u0437\u0443\u0439\u0442\u0435 vsl_get_snapshot \u0434\u043B\u044F \u043F\u043E\u043B\u0443\u0447\u0435\u043D\u0438\u044F \u0441\u043E\u0432\u043C\u0435\u0441\u0442\u0438\u043C\u044B\u0445 ID.",
5427
5454
  inputSchema: {
5428
5455
  type: "object",
5429
5456
  properties: {
@@ -6409,7 +6436,7 @@ var SessionManager = class {
6409
6436
  };
6410
6437
 
6411
6438
  // src/version.ts
6412
- var VSL_MCP_SERVER_VERSION = "1.3.1";
6439
+ var VSL_MCP_SERVER_VERSION = "1.3.3";
6413
6440
 
6414
6441
  // src/index.ts
6415
6442
  async function main() {