@thinkingos/vsl-mcp-server 1.3.4 → 1.3.5
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 +101 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -3865,10 +3865,84 @@ async function handleExecuteAction(args, browser, session, sessionId) {
|
|
|
3865
3865
|
const selector = `[data-vsl-id="${localId}"], #${localId}, .${localId}`;
|
|
3866
3866
|
page = await browser.getPage(sessionId);
|
|
3867
3867
|
const target = targetFrame || page;
|
|
3868
|
+
const actionsRequiringElement = ["click", "fill", "type", "check", "uncheck", "upload", "select", "hover", "focus", "blur", "clear"];
|
|
3869
|
+
if (actionsRequiringElement.includes(args.action)) {
|
|
3870
|
+
try {
|
|
3871
|
+
const expectedTag = resolvedId.match(/^([a-z][a-z0-9]*(?:_[a-z][a-z0-9]*)*)_/)?.[1] || "";
|
|
3872
|
+
const elementValidation = await target.evaluate(({ sel, expectedTag: expectedTag2 }) => {
|
|
3873
|
+
const el = document.querySelector(sel);
|
|
3874
|
+
if (!el) return { exists: false, valid: false, actualTag: "" };
|
|
3875
|
+
const actualTag = el.tagName.toLowerCase();
|
|
3876
|
+
return { exists: true, valid: actualTag === expectedTag2, actualTag };
|
|
3877
|
+
}, { sel: selector, expectedTag });
|
|
3878
|
+
if (!elementValidation.exists) {
|
|
3879
|
+
const extraction = await extractDomTree(browser, sessionId);
|
|
3880
|
+
const input = {
|
|
3881
|
+
viewport: extraction.viewport,
|
|
3882
|
+
url: snapshotUrl || "",
|
|
3883
|
+
title: "",
|
|
3884
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3885
|
+
scroll: extraction.scroll
|
|
3886
|
+
};
|
|
3887
|
+
session.snapshotFromElements(extraction.elements, input);
|
|
3888
|
+
await injectVslIdsIntoDom(browser, extraction.elements, /* @__PURE__ */ new Map(), sessionId);
|
|
3889
|
+
const revalidation = await target.evaluate(({ sel, expectedTag: expectedTag2 }) => {
|
|
3890
|
+
const el = document.querySelector(sel);
|
|
3891
|
+
if (!el) return { exists: false, valid: false, actualTag: "" };
|
|
3892
|
+
const actualTag = el.tagName.toLowerCase();
|
|
3893
|
+
return { exists: true, valid: actualTag === expectedTag2, actualTag };
|
|
3894
|
+
}, { sel: selector, expectedTag });
|
|
3895
|
+
if (!revalidation.exists) {
|
|
3896
|
+
return {
|
|
3897
|
+
status: "error",
|
|
3898
|
+
error: `Element not found after re-injection: ${args.target_id} (selector: ${selector})`
|
|
3899
|
+
};
|
|
3900
|
+
}
|
|
3901
|
+
if (!revalidation.valid) {
|
|
3902
|
+
return {
|
|
3903
|
+
status: "error",
|
|
3904
|
+
error: `Tag mismatch after re-injection: expected ${expectedTag}, got ${revalidation.actualTag} for ${args.target_id}`
|
|
3905
|
+
};
|
|
3906
|
+
}
|
|
3907
|
+
} else if (!elementValidation.valid) {
|
|
3908
|
+
const extraction = await extractDomTree(browser, sessionId);
|
|
3909
|
+
const input = {
|
|
3910
|
+
viewport: extraction.viewport,
|
|
3911
|
+
url: snapshotUrl || "",
|
|
3912
|
+
title: "",
|
|
3913
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3914
|
+
scroll: extraction.scroll
|
|
3915
|
+
};
|
|
3916
|
+
session.snapshotFromElements(extraction.elements, input);
|
|
3917
|
+
await injectVslIdsIntoDom(browser, extraction.elements, /* @__PURE__ */ new Map(), sessionId);
|
|
3918
|
+
const revalidation = await target.evaluate(({ sel, expectedTag: expectedTag2 }) => {
|
|
3919
|
+
const el = document.querySelector(sel);
|
|
3920
|
+
if (!el) return { exists: false, valid: false, actualTag: "" };
|
|
3921
|
+
const actualTag = el.tagName.toLowerCase();
|
|
3922
|
+
return { exists: true, valid: actualTag === expectedTag2, actualTag };
|
|
3923
|
+
}, { sel: selector, expectedTag });
|
|
3924
|
+
if (!revalidation.valid) {
|
|
3925
|
+
return {
|
|
3926
|
+
status: "error",
|
|
3927
|
+
error: `Tag mismatch after re-injection: expected ${expectedTag}, got ${revalidation.actualTag} for ${args.target_id}`
|
|
3928
|
+
};
|
|
3929
|
+
}
|
|
3930
|
+
}
|
|
3931
|
+
} catch (validationError) {
|
|
3932
|
+
console.warn(`[VSL] Element validation skipped (target.evaluate not available): ${validationError}`);
|
|
3933
|
+
}
|
|
3934
|
+
}
|
|
3868
3935
|
switch (args.action) {
|
|
3869
3936
|
case "click": {
|
|
3870
3937
|
try {
|
|
3871
|
-
await target.locator(selector).
|
|
3938
|
+
const clickElementCount = await target.locator(selector).count();
|
|
3939
|
+
if (clickElementCount === 0) {
|
|
3940
|
+
return {
|
|
3941
|
+
status: "error",
|
|
3942
|
+
error: `Element not found for click: ${args.target_id} (selector: ${selector})`
|
|
3943
|
+
};
|
|
3944
|
+
}
|
|
3945
|
+
await target.locator(selector).click({ timeout: 1e3 });
|
|
3872
3946
|
} catch (locatorError) {
|
|
3873
3947
|
let findObjectById2 = function(objects, targetId) {
|
|
3874
3948
|
for (const obj of objects) {
|
|
@@ -3921,7 +3995,14 @@ async function handleExecuteAction(args, browser, session, sessionId) {
|
|
|
3921
3995
|
error: "value is required for type action"
|
|
3922
3996
|
};
|
|
3923
3997
|
}
|
|
3924
|
-
await target.locator(selector).
|
|
3998
|
+
const fillElementCount = await target.locator(selector).count();
|
|
3999
|
+
if (fillElementCount === 0) {
|
|
4000
|
+
return {
|
|
4001
|
+
status: "error",
|
|
4002
|
+
error: `Element not found for fill: ${args.target_id} (selector: ${selector})`
|
|
4003
|
+
};
|
|
4004
|
+
}
|
|
4005
|
+
await target.locator(selector).fill(args.value, { timeout: 1e3 });
|
|
3925
4006
|
break;
|
|
3926
4007
|
case "scroll": {
|
|
3927
4008
|
const DEFAULT_SCROLL_AMOUNT = 500;
|
|
@@ -4150,7 +4231,14 @@ async function handleExecuteAction(args, browser, session, sessionId) {
|
|
|
4150
4231
|
error: "value must contain at least one file path"
|
|
4151
4232
|
};
|
|
4152
4233
|
}
|
|
4153
|
-
await target.locator(selector).
|
|
4234
|
+
const uploadElementCount = await target.locator(selector).count();
|
|
4235
|
+
if (uploadElementCount === 0) {
|
|
4236
|
+
return {
|
|
4237
|
+
status: "error",
|
|
4238
|
+
error: `Element not found for upload: ${args.target_id} (selector: ${selector})`
|
|
4239
|
+
};
|
|
4240
|
+
}
|
|
4241
|
+
await target.locator(selector).setInputFiles(filePaths.length === 1 ? filePaths[0] : filePaths, { timeout: 1e3 });
|
|
4154
4242
|
const result2 = {
|
|
4155
4243
|
status: "success",
|
|
4156
4244
|
data: {
|
|
@@ -4444,6 +4532,16 @@ async function handleExecuteAction(args, browser, session, sessionId) {
|
|
|
4444
4532
|
await page.reload({ timeout: args.timeout || 5e3 });
|
|
4445
4533
|
break;
|
|
4446
4534
|
}
|
|
4535
|
+
case "check":
|
|
4536
|
+
case "uncheck": {
|
|
4537
|
+
const shouldBeChecked = args.action === "check";
|
|
4538
|
+
if (shouldBeChecked) {
|
|
4539
|
+
await target.locator(selector).check({ timeout: 1e3 });
|
|
4540
|
+
} else {
|
|
4541
|
+
await target.locator(selector).uncheck({ timeout: 1e3 });
|
|
4542
|
+
}
|
|
4543
|
+
break;
|
|
4544
|
+
}
|
|
4447
4545
|
default:
|
|
4448
4546
|
return {
|
|
4449
4547
|
status: "error",
|