@cutleryapp/agent 1.0.42 → 1.0.43
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/mcp-executor.js +34 -33
- package/package.json +1 -1
package/dist/mcp-executor.js
CHANGED
|
@@ -448,10 +448,23 @@ class TestExecutor {
|
|
|
448
448
|
}
|
|
449
449
|
}
|
|
450
450
|
catch (err) {
|
|
451
|
-
//
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
451
|
+
// AI last-resort recovery — only when Playwright strategies all failed
|
|
452
|
+
if (process.env.OPENAI_API_KEY) {
|
|
453
|
+
console.log(` 🤖 Playwright failed, trying AI: ${err.message.split('\n')[0]}`);
|
|
454
|
+
try {
|
|
455
|
+
await aiSingleShot(page, raw);
|
|
456
|
+
}
|
|
457
|
+
catch (aiErr) {
|
|
458
|
+
console.log(` ⚠️ AI recovery also failed: ${aiErr.message.split('\n')[0]}`);
|
|
459
|
+
stepError = err.message;
|
|
460
|
+
result.success = false;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
else {
|
|
464
|
+
console.log(` ⚠️ Step failed: ${err.message.split('\n')[0]}`);
|
|
465
|
+
stepError = err.message;
|
|
466
|
+
result.success = false;
|
|
467
|
+
}
|
|
455
468
|
}
|
|
456
469
|
// Screenshot on failure, on the last step, or every 5 steps — not every step
|
|
457
470
|
let screenshotB64 = "";
|
|
@@ -1249,39 +1262,27 @@ async function tryFill(page, label, value) {
|
|
|
1249
1262
|
const labelRe = new RegExp(escapeRegex(label), "i");
|
|
1250
1263
|
const variants = labelVariants(label);
|
|
1251
1264
|
const attrContains = (attr) => variants.map(v => `input[${attr}*="${cssEscape(v)}" i], textarea[${attr}*="${cssEscape(v)}" i], [contenteditable="true"][${attr}*="${cssEscape(v)}" i]`).join(", ");
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
() => page.
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
catch { /* all 3 failed, try phase 2 */ }
|
|
1267
|
-
// Phase 2: attribute-based selectors covering name/id/data-test variants (300ms each)
|
|
1268
|
-
const exactAttrs = variants.flatMap(v => [
|
|
1269
|
-
`input[name="${cssEscape(v)}" i]`, `input[id="${cssEscape(v)}" i]`,
|
|
1270
|
-
`textarea[name="${cssEscape(v)}" i]`, `textarea[id="${cssEscape(v)}" i]`,
|
|
1271
|
-
]).join(", ");
|
|
1272
|
-
const phase2 = [
|
|
1273
|
-
() => page.locator(exactAttrs).first().fill(value),
|
|
1274
|
-
() => page.locator(`${attrContains("name")}, ${attrContains("id")}`).first().fill(value),
|
|
1275
|
-
() => page.locator(attrContains("data-test")).first().fill(value),
|
|
1276
|
-
() => page.locator(attrContains("aria-label")).first().fill(value),
|
|
1277
|
-
() => page.locator(attrContains("placeholder")).first().fill(value),
|
|
1265
|
+
// Sequential strategies — do NOT run concurrently (concurrent fills can cross-contaminate fields)
|
|
1266
|
+
// Each uses a short timeout since if the element exists, Playwright resolves near-instantly.
|
|
1267
|
+
const strategies = [
|
|
1268
|
+
['getByLabel', () => page.getByLabel(labelRe).first().fill(value)],
|
|
1269
|
+
['getByPlaceholder', () => page.getByPlaceholder(labelRe).first().fill(value)],
|
|
1270
|
+
['getByRole', () => page.getByRole("textbox", { name: labelRe }).first().fill(value)],
|
|
1271
|
+
['id/name exact', () => page.locator(variants.flatMap(v => [
|
|
1272
|
+
`input[name="${cssEscape(v)}" i]`, `input[id="${cssEscape(v)}" i]`,
|
|
1273
|
+
`textarea[name="${cssEscape(v)}" i]`, `textarea[id="${cssEscape(v)}" i]`,
|
|
1274
|
+
]).join(", ")).first().fill(value)],
|
|
1275
|
+
['id/name contains', () => page.locator(`${attrContains("name")}, ${attrContains("id")}`).first().fill(value)],
|
|
1276
|
+
['data-test', () => page.locator(attrContains("data-test")).first().fill(value)],
|
|
1277
|
+
['aria-label', () => page.locator(attrContains("aria-label")).first().fill(value)],
|
|
1278
|
+
['placeholder attr', () => page.locator(attrContains("placeholder")).first().fill(value)],
|
|
1278
1279
|
];
|
|
1279
|
-
for (const fn of
|
|
1280
|
+
for (const [, fn] of strategies) {
|
|
1280
1281
|
try {
|
|
1281
|
-
await
|
|
1282
|
+
await Promise.race([fn(), new Promise((_, r) => setTimeout(() => r(new Error('t')), 400))]);
|
|
1282
1283
|
return;
|
|
1283
1284
|
}
|
|
1284
|
-
catch { /* next */ }
|
|
1285
|
+
catch { /* next strategy */ }
|
|
1285
1286
|
}
|
|
1286
1287
|
throw new Error(`Could not find input field: "${label}"`);
|
|
1287
1288
|
}
|