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
package/dist/es/index.js
CHANGED
@@ -105,6 +105,10 @@ var ScriptPlayer = class {
|
|
105
105
|
} else if ("aiQuery" in flowItem) {
|
106
106
|
const queryTask = flowItem;
|
107
107
|
const prompt = queryTask.aiQuery;
|
108
|
+
const options = {
|
109
|
+
domIncluded: queryTask.domIncluded,
|
110
|
+
screenshotIncluded: queryTask.screenshotIncluded
|
111
|
+
};
|
108
112
|
assert(prompt, "missing prompt for aiQuery");
|
109
113
|
assert(
|
110
114
|
typeof prompt === "string",
|
@@ -115,6 +119,10 @@ var ScriptPlayer = class {
|
|
115
119
|
} else if ("aiNumber" in flowItem) {
|
116
120
|
const numberTask = flowItem;
|
117
121
|
const prompt = numberTask.aiNumber;
|
122
|
+
const options = {
|
123
|
+
domIncluded: numberTask.domIncluded,
|
124
|
+
screenshotIncluded: numberTask.screenshotIncluded
|
125
|
+
};
|
118
126
|
assert(prompt, "missing prompt for number");
|
119
127
|
assert(
|
120
128
|
typeof prompt === "string",
|
@@ -125,6 +133,10 @@ var ScriptPlayer = class {
|
|
125
133
|
} else if ("aiString" in flowItem) {
|
126
134
|
const stringTask = flowItem;
|
127
135
|
const prompt = stringTask.aiString;
|
136
|
+
const options = {
|
137
|
+
domIncluded: stringTask.domIncluded,
|
138
|
+
screenshotIncluded: stringTask.screenshotIncluded
|
139
|
+
};
|
128
140
|
assert(prompt, "missing prompt for string");
|
129
141
|
assert(
|
130
142
|
typeof prompt === "string",
|
@@ -135,6 +147,10 @@ var ScriptPlayer = class {
|
|
135
147
|
} else if ("aiBoolean" in flowItem) {
|
136
148
|
const booleanTask = flowItem;
|
137
149
|
const prompt = booleanTask.aiBoolean;
|
150
|
+
const options = {
|
151
|
+
domIncluded: booleanTask.domIncluded,
|
152
|
+
screenshotIncluded: booleanTask.screenshotIncluded
|
153
|
+
};
|
138
154
|
assert(prompt, "missing prompt for boolean");
|
139
155
|
assert(
|
140
156
|
typeof prompt === "string",
|
@@ -177,6 +193,9 @@ var ScriptPlayer = class {
|
|
177
193
|
} else if ("aiTap" in flowItem) {
|
178
194
|
const tapTask = flowItem;
|
179
195
|
await agent.aiTap(tapTask.aiTap, tapTask);
|
196
|
+
} else if ("aiRightClick" in flowItem) {
|
197
|
+
const rightClickTask = flowItem;
|
198
|
+
await agent.aiRightClick(rightClickTask.aiRightClick, rightClickTask);
|
180
199
|
} else if ("aiHover" in flowItem) {
|
181
200
|
const hoverTask = flowItem;
|
182
201
|
await agent.aiHover(hoverTask.aiHover, hoverTask);
|
@@ -199,6 +218,11 @@ var ScriptPlayer = class {
|
|
199
218
|
evaluateJavaScriptTask.javascript
|
200
219
|
);
|
201
220
|
this.setResult(evaluateJavaScriptTask.name, result);
|
221
|
+
} else if ("logScreenshot" in flowItem) {
|
222
|
+
const logScreenshotTask = flowItem;
|
223
|
+
await agent.logScreenshot(logScreenshotTask.logScreenshot, {
|
224
|
+
content: logScreenshotTask.content || ""
|
225
|
+
});
|
202
226
|
} else {
|
203
227
|
throw new Error(`unknown flowItem: ${JSON.stringify(flowItem)}`);
|
204
228
|
}
|
@@ -467,7 +491,8 @@ var WebElementInfo = class {
|
|
467
491
|
id,
|
468
492
|
attributes,
|
469
493
|
indexId,
|
470
|
-
xpaths
|
494
|
+
xpaths,
|
495
|
+
isVisible
|
471
496
|
}) {
|
472
497
|
this.content = content;
|
473
498
|
this.rect = rect;
|
@@ -480,6 +505,7 @@ var WebElementInfo = class {
|
|
480
505
|
this.attributes = attributes;
|
481
506
|
this.indexId = indexId;
|
482
507
|
this.xpaths = xpaths;
|
508
|
+
this.isVisible = isVisible;
|
483
509
|
}
|
484
510
|
};
|
485
511
|
|
@@ -502,14 +528,15 @@ async function parseContextFromWebPage(page, _opt) {
|
|
502
528
|
})
|
503
529
|
]);
|
504
530
|
const webTree = traverseTree(tree, (elementInfo) => {
|
505
|
-
const { rect, id, content, attributes, locator, indexId } = elementInfo;
|
531
|
+
const { rect, id, content, attributes, locator, indexId, isVisible } = elementInfo;
|
506
532
|
return new WebElementInfo({
|
507
533
|
rect,
|
508
534
|
locator,
|
509
535
|
id,
|
510
536
|
content,
|
511
537
|
attributes,
|
512
|
-
indexId
|
538
|
+
indexId,
|
539
|
+
isVisible
|
513
540
|
});
|
514
541
|
});
|
515
542
|
assert3(screenshotBase64, "screenshotBase64 is required");
|
@@ -539,7 +566,7 @@ function printReportMsg(filepath) {
|
|
539
566
|
logMsg(`Midscene - report file updated: ${filepath}`);
|
540
567
|
}
|
541
568
|
function replaceIllegalPathCharsAndSpace(str) {
|
542
|
-
return str.replace(/[
|
569
|
+
return str.replace(/[:*?"<>| ]/g, "-");
|
543
570
|
}
|
544
571
|
function forceClosePopup(page, debug7) {
|
545
572
|
page.on("popup", async (popup) => {
|
@@ -853,10 +880,10 @@ var PageTaskExecutor = class {
|
|
853
880
|
if (!taskParam || !taskParam.value) {
|
854
881
|
return;
|
855
882
|
}
|
856
|
-
await this.page.keyboard.type(taskParam.value);
|
857
|
-
} else {
|
858
|
-
await this.page.keyboard.type(taskParam.value);
|
859
883
|
}
|
884
|
+
await this.page.keyboard.type(taskParam.value, {
|
885
|
+
autoDismissKeyboard: taskParam.autoDismissKeyboard
|
886
|
+
});
|
860
887
|
}
|
861
888
|
};
|
862
889
|
tasks.push(taskActionInput);
|
@@ -885,6 +912,22 @@ var PageTaskExecutor = class {
|
|
885
912
|
}
|
886
913
|
};
|
887
914
|
tasks.push(taskActionTap);
|
915
|
+
} else if (plan2.type === "RightClick") {
|
916
|
+
const taskActionRightClick = {
|
917
|
+
type: "Action",
|
918
|
+
subType: "RightClick",
|
919
|
+
thought: plan2.thought,
|
920
|
+
locate: plan2.locate,
|
921
|
+
executor: async (param, { element }) => {
|
922
|
+
assert4(element, "Element not found, cannot right click");
|
923
|
+
await this.page.mouse.click(
|
924
|
+
element.center[0],
|
925
|
+
element.center[1],
|
926
|
+
{ button: "right" }
|
927
|
+
);
|
928
|
+
}
|
929
|
+
};
|
930
|
+
tasks.push(taskActionRightClick);
|
888
931
|
} else if (plan2.type === "Drag") {
|
889
932
|
const taskActionDrag = {
|
890
933
|
type: "Action",
|
@@ -1413,7 +1456,7 @@ var PageTaskExecutor = class {
|
|
1413
1456
|
executor: taskExecutor
|
1414
1457
|
};
|
1415
1458
|
}
|
1416
|
-
async createTypeQueryTask(type, demand) {
|
1459
|
+
async createTypeQueryTask(type, demand, opt) {
|
1417
1460
|
const taskExecutor = new Executor(
|
1418
1461
|
taskTitleStr(
|
1419
1462
|
type,
|
@@ -1444,7 +1487,10 @@ var PageTaskExecutor = class {
|
|
1444
1487
|
result: `${type}, ${demand}`
|
1445
1488
|
};
|
1446
1489
|
}
|
1447
|
-
const { data, usage } = await this.insight.extract(
|
1490
|
+
const { data, usage } = await this.insight.extract(
|
1491
|
+
demandInput,
|
1492
|
+
opt
|
1493
|
+
);
|
1448
1494
|
let outputResult = data;
|
1449
1495
|
if (ifTypeRestricted) {
|
1450
1496
|
assert4(data?.result !== void 0, "No result in query data");
|
@@ -1464,17 +1510,17 @@ var PageTaskExecutor = class {
|
|
1464
1510
|
executor: taskExecutor
|
1465
1511
|
};
|
1466
1512
|
}
|
1467
|
-
async query(demand) {
|
1468
|
-
return this.createTypeQueryTask("Query", demand);
|
1513
|
+
async query(demand, opt) {
|
1514
|
+
return this.createTypeQueryTask("Query", demand, opt);
|
1469
1515
|
}
|
1470
|
-
async boolean(prompt) {
|
1471
|
-
return this.createTypeQueryTask("Boolean", prompt);
|
1516
|
+
async boolean(prompt, opt) {
|
1517
|
+
return this.createTypeQueryTask("Boolean", prompt, opt);
|
1472
1518
|
}
|
1473
|
-
async number(prompt) {
|
1474
|
-
return this.createTypeQueryTask("Number", prompt);
|
1519
|
+
async number(prompt, opt) {
|
1520
|
+
return this.createTypeQueryTask("Number", prompt, opt);
|
1475
1521
|
}
|
1476
|
-
async string(prompt) {
|
1477
|
-
return this.createTypeQueryTask("String", prompt);
|
1522
|
+
async string(prompt, opt) {
|
1523
|
+
return this.createTypeQueryTask("String", prompt, opt);
|
1478
1524
|
}
|
1479
1525
|
async assert(assertion) {
|
1480
1526
|
const description = `assert: ${assertion}`;
|
@@ -1610,7 +1656,7 @@ function buildPlans(type, locateParam, param) {
|
|
1610
1656
|
param: locateParam,
|
1611
1657
|
thought: ""
|
1612
1658
|
} : null;
|
1613
|
-
if (type === "Tap" || type === "Hover") {
|
1659
|
+
if (type === "Tap" || type === "Hover" || type === "RightClick") {
|
1614
1660
|
assert5(locateParam, `missing locate info for action "${type}"`);
|
1615
1661
|
assert5(locatePlan, `missing locate info for action "${type}"`);
|
1616
1662
|
const tapPlan = {
|
@@ -1681,8 +1727,8 @@ function buildPlans(type, locateParam, param) {
|
|
1681
1727
|
|
1682
1728
|
// src/common/task-cache.ts
|
1683
1729
|
import assert6 from "assert";
|
1684
|
-
import { existsSync as existsSync2, readFileSync, writeFileSync as writeFileSync2 } from "fs";
|
1685
|
-
import { join as join2 } from "path";
|
1730
|
+
import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync, writeFileSync as writeFileSync2 } from "fs";
|
1731
|
+
import { dirname as dirname2, join as join2 } from "path";
|
1686
1732
|
import { getMidsceneRunSubDir as getMidsceneRunSubDir2 } from "misoai-shared/common";
|
1687
1733
|
import { getDebug as getDebug3 } from "misoai-shared/logger";
|
1688
1734
|
import { ifInBrowser as ifInBrowser2 } from "misoai-shared/utils";
|
@@ -1690,7 +1736,7 @@ import yaml3 from "js-yaml";
|
|
1690
1736
|
import semver from "semver";
|
1691
1737
|
|
1692
1738
|
// package.json
|
1693
|
-
var version = "1.
|
1739
|
+
var version = "1.0.3";
|
1694
1740
|
|
1695
1741
|
// src/common/task-cache.ts
|
1696
1742
|
var debug3 = getDebug3("cache");
|
@@ -1821,8 +1867,14 @@ cache file: ${cacheFile}`
|
|
1821
1867
|
return;
|
1822
1868
|
}
|
1823
1869
|
try {
|
1870
|
+
const dir = dirname2(this.cacheFilePath);
|
1871
|
+
if (!existsSync2(dir)) {
|
1872
|
+
mkdirSync2(dir, { recursive: true });
|
1873
|
+
debug3("created cache directory: %s", dir);
|
1874
|
+
}
|
1824
1875
|
const yamlData = yaml3.dump(this.cache);
|
1825
1876
|
writeFileSync2(this.cacheFilePath, yamlData);
|
1877
|
+
debug3("cache flushed to file: %s", this.cacheFilePath);
|
1826
1878
|
} catch (err) {
|
1827
1879
|
debug3(
|
1828
1880
|
"write cache to file failed, path: %s, error: %s",
|
@@ -2080,6 +2132,23 @@ var PageAgent = class {
|
|
2080
2132
|
metadata
|
2081
2133
|
};
|
2082
2134
|
}
|
2135
|
+
async aiRightClick(locatePrompt, opt) {
|
2136
|
+
const detailedLocateParam = this.buildDetailedLocateParam(
|
2137
|
+
locatePrompt,
|
2138
|
+
opt
|
2139
|
+
);
|
2140
|
+
const plans = buildPlans("RightClick", detailedLocateParam);
|
2141
|
+
const { executor, output } = await this.taskExecutor.runPlans(
|
2142
|
+
taskTitleStr("RightClick", locateParamStr(detailedLocateParam)),
|
2143
|
+
plans,
|
2144
|
+
{ cacheable: opt?.cacheable }
|
2145
|
+
);
|
2146
|
+
const metadata = this.afterTaskRunning(executor);
|
2147
|
+
return {
|
2148
|
+
result: output,
|
2149
|
+
metadata
|
2150
|
+
};
|
2151
|
+
}
|
2083
2152
|
async aiInput(value, locatePrompt, opt) {
|
2084
2153
|
assert7(
|
2085
2154
|
typeof value === "string",
|
@@ -2511,6 +2580,40 @@ ${errors}`);
|
|
2511
2580
|
}
|
2512
2581
|
throw new Error("evaluateJavaScript is not supported in current agent");
|
2513
2582
|
}
|
2583
|
+
async logScreenshot(title, options) {
|
2584
|
+
const screenshotTitle = title || "untitled";
|
2585
|
+
const content = options?.content || "";
|
2586
|
+
const screenshot = await this.page.screenshotBase64?.();
|
2587
|
+
if (screenshot) {
|
2588
|
+
const executionDump = {
|
2589
|
+
name: screenshotTitle,
|
2590
|
+
description: content,
|
2591
|
+
tasks: [{
|
2592
|
+
type: "Screenshot",
|
2593
|
+
subType: "log",
|
2594
|
+
status: "finished",
|
2595
|
+
executor: null,
|
2596
|
+
param: {
|
2597
|
+
title: screenshotTitle,
|
2598
|
+
content
|
2599
|
+
},
|
2600
|
+
output: {
|
2601
|
+
screenshot
|
2602
|
+
},
|
2603
|
+
thought: `Logged screenshot: ${screenshotTitle}`,
|
2604
|
+
timing: {
|
2605
|
+
start: Date.now(),
|
2606
|
+
end: Date.now(),
|
2607
|
+
cost: 0
|
2608
|
+
}
|
2609
|
+
}],
|
2610
|
+
sdkVersion: "1.0.0",
|
2611
|
+
logTime: Date.now(),
|
2612
|
+
model_name: "screenshot"
|
2613
|
+
};
|
2614
|
+
this.appendExecutionDump(executionDump);
|
2615
|
+
}
|
2616
|
+
}
|
2514
2617
|
async destroy() {
|
2515
2618
|
await this.page.destroy();
|
2516
2619
|
}
|
@@ -2937,6 +3040,14 @@ var PlaywrightAiFixture = (options) => {
|
|
2937
3040
|
aiActionType: "aiTap"
|
2938
3041
|
});
|
2939
3042
|
},
|
3043
|
+
aiRightClick: async ({ page }, use, testInfo) => {
|
3044
|
+
await generateAiFunction({
|
3045
|
+
page,
|
3046
|
+
testInfo,
|
3047
|
+
use,
|
3048
|
+
aiActionType: "aiRightClick"
|
3049
|
+
});
|
3050
|
+
},
|
2940
3051
|
aiHover: async ({ page }, use, testInfo) => {
|
2941
3052
|
await generateAiFunction({
|
2942
3053
|
page,
|
@@ -3024,6 +3135,14 @@ var PlaywrightAiFixture = (options) => {
|
|
3024
3135
|
use,
|
3025
3136
|
aiActionType: "aiBoolean"
|
3026
3137
|
});
|
3138
|
+
},
|
3139
|
+
logScreenshot: async ({ page }, use, testInfo) => {
|
3140
|
+
await generateAiFunction({
|
3141
|
+
page,
|
3142
|
+
testInfo,
|
3143
|
+
use,
|
3144
|
+
aiActionType: "logScreenshot"
|
3145
|
+
});
|
3027
3146
|
}
|
3028
3147
|
};
|
3029
3148
|
};
|