misoai-web 1.5.6 → 1.5.7
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/es/agent.js +124 -21
- package/dist/es/agent.js.map +1 -1
- package/dist/es/bridge-mode-browser.js +10 -9
- package/dist/es/bridge-mode-browser.js.map +1 -1
- package/dist/es/bridge-mode.js +126 -23
- package/dist/es/bridge-mode.js.map +1 -1
- package/dist/es/chrome-extension.js +132 -28
- package/dist/es/chrome-extension.js.map +1 -1
- package/dist/es/index.js +140 -21
- package/dist/es/index.js.map +1 -1
- package/dist/es/midscene-playground.js +124 -21
- package/dist/es/midscene-playground.js.map +1 -1
- package/dist/es/midscene-server.js.map +1 -1
- package/dist/es/playground.js +124 -21
- package/dist/es/playground.js.map +1 -1
- package/dist/es/playwright-report.js +1 -1
- package/dist/es/playwright-report.js.map +1 -1
- package/dist/es/playwright.js +140 -21
- package/dist/es/playwright.js.map +1 -1
- package/dist/es/puppeteer-agent-launcher.js +124 -21
- package/dist/es/puppeteer-agent-launcher.js.map +1 -1
- package/dist/es/puppeteer.js +124 -21
- package/dist/es/puppeteer.js.map +1 -1
- package/dist/es/ui-utils.js.map +1 -1
- package/dist/es/utils.js +7 -4
- package/dist/es/utils.js.map +1 -1
- package/dist/es/yaml.js +24 -0
- package/dist/es/yaml.js.map +1 -1
- package/dist/lib/agent.js +122 -19
- package/dist/lib/agent.js.map +1 -1
- package/dist/lib/bridge-mode-browser.js +10 -9
- package/dist/lib/bridge-mode-browser.js.map +1 -1
- package/dist/lib/bridge-mode.js +124 -21
- package/dist/lib/bridge-mode.js.map +1 -1
- package/dist/lib/chrome-extension.js +130 -26
- package/dist/lib/chrome-extension.js.map +1 -1
- package/dist/lib/index.js +138 -19
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/midscene-playground.js +122 -19
- package/dist/lib/midscene-playground.js.map +1 -1
- package/dist/lib/midscene-server.js.map +1 -1
- package/dist/lib/playground.js +122 -19
- package/dist/lib/playground.js.map +1 -1
- package/dist/lib/playwright-report.js +1 -1
- package/dist/lib/playwright-report.js.map +1 -1
- package/dist/lib/playwright.js +138 -19
- package/dist/lib/playwright.js.map +1 -1
- package/dist/lib/puppeteer-agent-launcher.js +122 -19
- package/dist/lib/puppeteer-agent-launcher.js.map +1 -1
- package/dist/lib/puppeteer.js +122 -19
- package/dist/lib/puppeteer.js.map +1 -1
- package/dist/lib/ui-utils.js.map +1 -1
- package/dist/lib/utils.js +7 -4
- package/dist/lib/utils.js.map +1 -1
- package/dist/lib/yaml.js +24 -0
- package/dist/lib/yaml.js.map +1 -1
- package/dist/types/agent.d.ts +10 -7
- package/dist/types/bridge-mode-browser.d.ts +2 -3
- package/dist/types/bridge-mode.d.ts +2 -3
- package/dist/types/{browser-aec1055d.d.ts → browser-9b472ffb.d.ts} +1 -1
- package/dist/types/chrome-extension.d.ts +2 -3
- package/dist/types/index.d.ts +1 -2
- package/dist/types/midscene-server.d.ts +1 -2
- package/dist/types/{page-86ab0fe1.d.ts → page-ed0ecb44.d.ts} +19 -9
- package/dist/types/playground.d.ts +2 -3
- package/dist/types/playwright.d.ts +9 -2
- package/dist/types/puppeteer-agent-launcher.d.ts +1 -2
- package/dist/types/puppeteer.d.ts +6 -5
- package/dist/types/ui-utils.d.ts +1 -1
- package/dist/types/utils.d.ts +1 -2
- package/dist/types/yaml.d.ts +1 -2
- package/iife-script/htmlElement.js +51 -73
- package/iife-script/htmlElementDebug.js +33 -54
- package/package.json +23 -23
- package/LICENSE +0 -21
@@ -41,7 +41,8 @@ var WebElementInfo = class {
|
|
41
41
|
id,
|
42
42
|
attributes,
|
43
43
|
indexId,
|
44
|
-
xpaths
|
44
|
+
xpaths,
|
45
|
+
isVisible
|
45
46
|
}) {
|
46
47
|
this.content = content;
|
47
48
|
this.rect = rect;
|
@@ -54,6 +55,7 @@ var WebElementInfo = class {
|
|
54
55
|
this.attributes = attributes;
|
55
56
|
this.indexId = indexId;
|
56
57
|
this.xpaths = xpaths;
|
58
|
+
this.isVisible = isVisible;
|
57
59
|
}
|
58
60
|
};
|
59
61
|
|
@@ -76,14 +78,15 @@ async function parseContextFromWebPage(page, _opt) {
|
|
76
78
|
})
|
77
79
|
]);
|
78
80
|
const webTree = (0, import_extractor.traverseTree)(tree, (elementInfo) => {
|
79
|
-
const { rect, id, content, attributes, locator, indexId } = elementInfo;
|
81
|
+
const { rect, id, content, attributes, locator, indexId, isVisible } = elementInfo;
|
80
82
|
return new WebElementInfo({
|
81
83
|
rect,
|
82
84
|
locator,
|
83
85
|
id,
|
84
86
|
content,
|
85
87
|
attributes,
|
86
|
-
indexId
|
88
|
+
indexId,
|
89
|
+
isVisible
|
87
90
|
});
|
88
91
|
});
|
89
92
|
(0, import_utils2.assert)(screenshotBase64, "screenshotBase64 is required");
|
@@ -114,7 +117,7 @@ function printReportMsg(filepath) {
|
|
114
117
|
}
|
115
118
|
var ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED = "NOT_IMPLEMENTED_AS_DESIGNED";
|
116
119
|
function replaceIllegalPathCharsAndSpace(str) {
|
117
|
-
return str.replace(/[
|
120
|
+
return str.replace(/[:*?"<>| ]/g, "-");
|
118
121
|
}
|
119
122
|
function matchElementFromPlan(planLocateParam, tree) {
|
120
123
|
if (!planLocateParam) {
|
@@ -244,6 +247,10 @@ var ScriptPlayer = class {
|
|
244
247
|
} else if ("aiQuery" in flowItem) {
|
245
248
|
const queryTask = flowItem;
|
246
249
|
const prompt = queryTask.aiQuery;
|
250
|
+
const options = {
|
251
|
+
domIncluded: queryTask.domIncluded,
|
252
|
+
screenshotIncluded: queryTask.screenshotIncluded
|
253
|
+
};
|
247
254
|
(0, import_utils3.assert)(prompt, "missing prompt for aiQuery");
|
248
255
|
(0, import_utils3.assert)(
|
249
256
|
typeof prompt === "string",
|
@@ -254,6 +261,10 @@ var ScriptPlayer = class {
|
|
254
261
|
} else if ("aiNumber" in flowItem) {
|
255
262
|
const numberTask = flowItem;
|
256
263
|
const prompt = numberTask.aiNumber;
|
264
|
+
const options = {
|
265
|
+
domIncluded: numberTask.domIncluded,
|
266
|
+
screenshotIncluded: numberTask.screenshotIncluded
|
267
|
+
};
|
257
268
|
(0, import_utils3.assert)(prompt, "missing prompt for number");
|
258
269
|
(0, import_utils3.assert)(
|
259
270
|
typeof prompt === "string",
|
@@ -264,6 +275,10 @@ var ScriptPlayer = class {
|
|
264
275
|
} else if ("aiString" in flowItem) {
|
265
276
|
const stringTask = flowItem;
|
266
277
|
const prompt = stringTask.aiString;
|
278
|
+
const options = {
|
279
|
+
domIncluded: stringTask.domIncluded,
|
280
|
+
screenshotIncluded: stringTask.screenshotIncluded
|
281
|
+
};
|
267
282
|
(0, import_utils3.assert)(prompt, "missing prompt for string");
|
268
283
|
(0, import_utils3.assert)(
|
269
284
|
typeof prompt === "string",
|
@@ -274,6 +289,10 @@ var ScriptPlayer = class {
|
|
274
289
|
} else if ("aiBoolean" in flowItem) {
|
275
290
|
const booleanTask = flowItem;
|
276
291
|
const prompt = booleanTask.aiBoolean;
|
292
|
+
const options = {
|
293
|
+
domIncluded: booleanTask.domIncluded,
|
294
|
+
screenshotIncluded: booleanTask.screenshotIncluded
|
295
|
+
};
|
277
296
|
(0, import_utils3.assert)(prompt, "missing prompt for boolean");
|
278
297
|
(0, import_utils3.assert)(
|
279
298
|
typeof prompt === "string",
|
@@ -316,6 +335,9 @@ var ScriptPlayer = class {
|
|
316
335
|
} else if ("aiTap" in flowItem) {
|
317
336
|
const tapTask = flowItem;
|
318
337
|
await agent.aiTap(tapTask.aiTap, tapTask);
|
338
|
+
} else if ("aiRightClick" in flowItem) {
|
339
|
+
const rightClickTask = flowItem;
|
340
|
+
await agent.aiRightClick(rightClickTask.aiRightClick, rightClickTask);
|
319
341
|
} else if ("aiHover" in flowItem) {
|
320
342
|
const hoverTask = flowItem;
|
321
343
|
await agent.aiHover(hoverTask.aiHover, hoverTask);
|
@@ -338,6 +360,11 @@ var ScriptPlayer = class {
|
|
338
360
|
evaluateJavaScriptTask.javascript
|
339
361
|
);
|
340
362
|
this.setResult(evaluateJavaScriptTask.name, result);
|
363
|
+
} else if ("logScreenshot" in flowItem) {
|
364
|
+
const logScreenshotTask = flowItem;
|
365
|
+
await agent.logScreenshot(logScreenshotTask.logScreenshot, {
|
366
|
+
content: logScreenshotTask.content || ""
|
367
|
+
});
|
341
368
|
} else {
|
342
369
|
throw new Error(`unknown flowItem: ${JSON.stringify(flowItem)}`);
|
343
370
|
}
|
@@ -830,10 +857,10 @@ var PageTaskExecutor = class {
|
|
830
857
|
if (!taskParam || !taskParam.value) {
|
831
858
|
return;
|
832
859
|
}
|
833
|
-
await this.page.keyboard.type(taskParam.value);
|
834
|
-
} else {
|
835
|
-
await this.page.keyboard.type(taskParam.value);
|
836
860
|
}
|
861
|
+
await this.page.keyboard.type(taskParam.value, {
|
862
|
+
autoDismissKeyboard: taskParam.autoDismissKeyboard
|
863
|
+
});
|
837
864
|
}
|
838
865
|
};
|
839
866
|
tasks.push(taskActionInput);
|
@@ -862,6 +889,22 @@ var PageTaskExecutor = class {
|
|
862
889
|
}
|
863
890
|
};
|
864
891
|
tasks.push(taskActionTap);
|
892
|
+
} else if (plan2.type === "RightClick") {
|
893
|
+
const taskActionRightClick = {
|
894
|
+
type: "Action",
|
895
|
+
subType: "RightClick",
|
896
|
+
thought: plan2.thought,
|
897
|
+
locate: plan2.locate,
|
898
|
+
executor: async (param, { element }) => {
|
899
|
+
(0, import_utils6.assert)(element, "Element not found, cannot right click");
|
900
|
+
await this.page.mouse.click(
|
901
|
+
element.center[0],
|
902
|
+
element.center[1],
|
903
|
+
{ button: "right" }
|
904
|
+
);
|
905
|
+
}
|
906
|
+
};
|
907
|
+
tasks.push(taskActionRightClick);
|
865
908
|
} else if (plan2.type === "Drag") {
|
866
909
|
const taskActionDrag = {
|
867
910
|
type: "Action",
|
@@ -1390,7 +1433,7 @@ var PageTaskExecutor = class {
|
|
1390
1433
|
executor: taskExecutor
|
1391
1434
|
};
|
1392
1435
|
}
|
1393
|
-
async createTypeQueryTask(type, demand) {
|
1436
|
+
async createTypeQueryTask(type, demand, opt) {
|
1394
1437
|
const taskExecutor = new import_misoai_core.Executor(
|
1395
1438
|
taskTitleStr(
|
1396
1439
|
type,
|
@@ -1421,7 +1464,10 @@ var PageTaskExecutor = class {
|
|
1421
1464
|
result: `${type}, ${demand}`
|
1422
1465
|
};
|
1423
1466
|
}
|
1424
|
-
const { data, usage } = await this.insight.extract(
|
1467
|
+
const { data, usage } = await this.insight.extract(
|
1468
|
+
demandInput,
|
1469
|
+
opt
|
1470
|
+
);
|
1425
1471
|
let outputResult = data;
|
1426
1472
|
if (ifTypeRestricted) {
|
1427
1473
|
(0, import_utils6.assert)(data?.result !== void 0, "No result in query data");
|
@@ -1441,17 +1487,17 @@ var PageTaskExecutor = class {
|
|
1441
1487
|
executor: taskExecutor
|
1442
1488
|
};
|
1443
1489
|
}
|
1444
|
-
async query(demand) {
|
1445
|
-
return this.createTypeQueryTask("Query", demand);
|
1490
|
+
async query(demand, opt) {
|
1491
|
+
return this.createTypeQueryTask("Query", demand, opt);
|
1446
1492
|
}
|
1447
|
-
async boolean(prompt) {
|
1448
|
-
return this.createTypeQueryTask("Boolean", prompt);
|
1493
|
+
async boolean(prompt, opt) {
|
1494
|
+
return this.createTypeQueryTask("Boolean", prompt, opt);
|
1449
1495
|
}
|
1450
|
-
async number(prompt) {
|
1451
|
-
return this.createTypeQueryTask("Number", prompt);
|
1496
|
+
async number(prompt, opt) {
|
1497
|
+
return this.createTypeQueryTask("Number", prompt, opt);
|
1452
1498
|
}
|
1453
|
-
async string(prompt) {
|
1454
|
-
return this.createTypeQueryTask("String", prompt);
|
1499
|
+
async string(prompt, opt) {
|
1500
|
+
return this.createTypeQueryTask("String", prompt, opt);
|
1455
1501
|
}
|
1456
1502
|
async assert(assertion) {
|
1457
1503
|
const description = `assert: ${assertion}`;
|
@@ -1587,7 +1633,7 @@ function buildPlans(type, locateParam, param) {
|
|
1587
1633
|
param: locateParam,
|
1588
1634
|
thought: ""
|
1589
1635
|
} : null;
|
1590
|
-
if (type === "Tap" || type === "Hover") {
|
1636
|
+
if (type === "Tap" || type === "Hover" || type === "RightClick") {
|
1591
1637
|
(0, import_utils8.assert)(locateParam, `missing locate info for action "${type}"`);
|
1592
1638
|
(0, import_utils8.assert)(locatePlan, `missing locate info for action "${type}"`);
|
1593
1639
|
const tapPlan = {
|
@@ -1667,7 +1713,7 @@ var import_js_yaml3 = __toESM(require("js-yaml"));
|
|
1667
1713
|
var import_semver = __toESM(require("semver"));
|
1668
1714
|
|
1669
1715
|
// package.json
|
1670
|
-
var version = "1.
|
1716
|
+
var version = "1.0.3";
|
1671
1717
|
|
1672
1718
|
// src/common/task-cache.ts
|
1673
1719
|
var debug3 = (0, import_logger3.getDebug)("cache");
|
@@ -1798,8 +1844,14 @@ cache file: ${cacheFile}`
|
|
1798
1844
|
return;
|
1799
1845
|
}
|
1800
1846
|
try {
|
1847
|
+
const dir = (0, import_node_path2.dirname)(this.cacheFilePath);
|
1848
|
+
if (!(0, import_node_fs2.existsSync)(dir)) {
|
1849
|
+
(0, import_node_fs2.mkdirSync)(dir, { recursive: true });
|
1850
|
+
debug3("created cache directory: %s", dir);
|
1851
|
+
}
|
1801
1852
|
const yamlData = import_js_yaml3.default.dump(this.cache);
|
1802
1853
|
(0, import_node_fs2.writeFileSync)(this.cacheFilePath, yamlData);
|
1854
|
+
debug3("cache flushed to file: %s", this.cacheFilePath);
|
1803
1855
|
} catch (err) {
|
1804
1856
|
debug3(
|
1805
1857
|
"write cache to file failed, path: %s, error: %s",
|
@@ -2057,6 +2109,23 @@ var PageAgent = class {
|
|
2057
2109
|
metadata
|
2058
2110
|
};
|
2059
2111
|
}
|
2112
|
+
async aiRightClick(locatePrompt, opt) {
|
2113
|
+
const detailedLocateParam = this.buildDetailedLocateParam(
|
2114
|
+
locatePrompt,
|
2115
|
+
opt
|
2116
|
+
);
|
2117
|
+
const plans = buildPlans("RightClick", detailedLocateParam);
|
2118
|
+
const { executor, output } = await this.taskExecutor.runPlans(
|
2119
|
+
taskTitleStr("RightClick", locateParamStr(detailedLocateParam)),
|
2120
|
+
plans,
|
2121
|
+
{ cacheable: opt?.cacheable }
|
2122
|
+
);
|
2123
|
+
const metadata = this.afterTaskRunning(executor);
|
2124
|
+
return {
|
2125
|
+
result: output,
|
2126
|
+
metadata
|
2127
|
+
};
|
2128
|
+
}
|
2060
2129
|
async aiInput(value, locatePrompt, opt) {
|
2061
2130
|
(0, import_utils12.assert)(
|
2062
2131
|
typeof value === "string",
|
@@ -2488,6 +2557,40 @@ ${errors}`);
|
|
2488
2557
|
}
|
2489
2558
|
throw new Error("evaluateJavaScript is not supported in current agent");
|
2490
2559
|
}
|
2560
|
+
async logScreenshot(title, options) {
|
2561
|
+
const screenshotTitle = title || "untitled";
|
2562
|
+
const content = options?.content || "";
|
2563
|
+
const screenshot = await this.page.screenshotBase64?.();
|
2564
|
+
if (screenshot) {
|
2565
|
+
const executionDump = {
|
2566
|
+
name: screenshotTitle,
|
2567
|
+
description: content,
|
2568
|
+
tasks: [{
|
2569
|
+
type: "Screenshot",
|
2570
|
+
subType: "log",
|
2571
|
+
status: "finished",
|
2572
|
+
executor: null,
|
2573
|
+
param: {
|
2574
|
+
title: screenshotTitle,
|
2575
|
+
content
|
2576
|
+
},
|
2577
|
+
output: {
|
2578
|
+
screenshot
|
2579
|
+
},
|
2580
|
+
thought: `Logged screenshot: ${screenshotTitle}`,
|
2581
|
+
timing: {
|
2582
|
+
start: Date.now(),
|
2583
|
+
end: Date.now(),
|
2584
|
+
cost: 0
|
2585
|
+
}
|
2586
|
+
}],
|
2587
|
+
sdkVersion: "1.0.0",
|
2588
|
+
logTime: Date.now(),
|
2589
|
+
model_name: "screenshot"
|
2590
|
+
};
|
2591
|
+
this.appendExecutionDump(executionDump);
|
2592
|
+
}
|
2593
|
+
}
|
2491
2594
|
async destroy() {
|
2492
2595
|
await this.page.destroy();
|
2493
2596
|
}
|