@midscene/web 0.11.1 → 0.11.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/es/appium.js +85 -39
- package/dist/es/bridge-mode-browser.js +58 -19
- package/dist/es/bridge-mode.js +62 -43
- package/dist/es/chrome-extension.js +105 -51
- package/dist/es/index.js +292 -218
- package/dist/es/midscene-playground.js +57 -38
- package/dist/es/playground.js +57 -38
- package/dist/es/playwright-report.js +4 -0
- package/dist/es/playwright.js +252 -203
- package/dist/es/puppeteer.js +86 -60
- package/dist/es/ui-utils.js +43 -0
- package/dist/lib/appium.js +85 -39
- package/dist/lib/bridge-mode-browser.js +58 -19
- package/dist/lib/bridge-mode.js +62 -43
- package/dist/lib/chrome-extension.js +105 -51
- package/dist/lib/index.js +292 -218
- package/dist/lib/midscene-playground.js +57 -38
- package/dist/lib/playground.js +57 -38
- package/dist/lib/playwright-report.js +4 -0
- package/dist/lib/playwright.js +252 -203
- package/dist/lib/puppeteer.js +86 -60
- package/dist/lib/ui-utils.js +43 -0
- package/dist/types/{tasks-d5a01262.d.ts → agent-ae110e80.d.ts} +43 -43
- package/dist/types/appium.d.ts +3 -3
- package/dist/types/bridge-mode-browser.d.ts +3 -3
- package/dist/types/bridge-mode.d.ts +4 -4
- package/dist/types/{browser-7d5614fb.d.ts → browser-9d620553.d.ts} +4 -4
- package/dist/types/chrome-extension.d.ts +4 -4
- package/dist/types/index.d.ts +8 -8
- package/dist/types/{page-77af8d5f.d.ts → page-97720803.d.ts} +34 -8
- package/dist/types/playground.d.ts +4 -4
- package/dist/types/playwright.d.ts +13 -7
- package/dist/types/puppeteer.d.ts +3 -3
- package/dist/types/ui-utils.d.ts +6 -1
- package/dist/types/{utils-1a3bc661.d.ts → utils-93b3f5f3.d.ts} +1 -1
- package/dist/types/utils.d.ts +2 -2
- package/dist/types/yaml.d.ts +4 -4
- package/package.json +6 -6
package/dist/es/appium.js
CHANGED
|
@@ -3362,7 +3362,9 @@ var TaskCache = class {
|
|
|
3362
3362
|
if (!this.midscenePkgInfo) {
|
|
3363
3363
|
return void 0;
|
|
3364
3364
|
}
|
|
3365
|
-
|
|
3365
|
+
const jsonDataPkgVersion = jsonData.pkgVersion.split(".");
|
|
3366
|
+
const midscenePkgInfoPkgVersion = this.midscenePkgInfo.version.split(".");
|
|
3367
|
+
if (jsonDataPkgVersion[0] !== midscenePkgInfoPkgVersion[0] || jsonDataPkgVersion[1] !== midscenePkgInfoPkgVersion[1]) {
|
|
3366
3368
|
return void 0;
|
|
3367
3369
|
}
|
|
3368
3370
|
return jsonData;
|
|
@@ -3396,6 +3398,56 @@ var TaskCache = class {
|
|
|
3396
3398
|
}
|
|
3397
3399
|
};
|
|
3398
3400
|
|
|
3401
|
+
// src/common/ui-utils.ts
|
|
3402
|
+
function typeStr(task) {
|
|
3403
|
+
return task.subType ? `${task.type} / ${task.subType || ""}` : task.type;
|
|
3404
|
+
}
|
|
3405
|
+
function getKeyCommands(value) {
|
|
3406
|
+
const keys = Array.isArray(value) ? value : [value];
|
|
3407
|
+
return keys.reduce((acc, k) => {
|
|
3408
|
+
const includeMeta = keys.includes("Meta") || keys.includes("Control");
|
|
3409
|
+
if (includeMeta && (k === "a" || k === "A")) {
|
|
3410
|
+
return acc.concat([{ key: k, command: "SelectAll" }]);
|
|
3411
|
+
}
|
|
3412
|
+
if (includeMeta && (k === "c" || k === "C")) {
|
|
3413
|
+
return acc.concat([{ key: k, command: "Copy" }]);
|
|
3414
|
+
}
|
|
3415
|
+
if (includeMeta && (k === "v" || k === "V")) {
|
|
3416
|
+
return acc.concat([{ key: k, command: "Paste" }]);
|
|
3417
|
+
}
|
|
3418
|
+
return acc.concat([{ key: k }]);
|
|
3419
|
+
}, []);
|
|
3420
|
+
}
|
|
3421
|
+
function paramStr(task) {
|
|
3422
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
3423
|
+
let value;
|
|
3424
|
+
if (task.type === "Planning") {
|
|
3425
|
+
value = (_a = task == null ? void 0 : task.param) == null ? void 0 : _a.userPrompt;
|
|
3426
|
+
}
|
|
3427
|
+
if (task.type === "Insight") {
|
|
3428
|
+
value = ((_b = task == null ? void 0 : task.param) == null ? void 0 : _b.prompt) || ((_c = task == null ? void 0 : task.param) == null ? void 0 : _c.id) || ((_d = task == null ? void 0 : task.param) == null ? void 0 : _d.dataDemand) || ((_e = task == null ? void 0 : task.param) == null ? void 0 : _e.assertion);
|
|
3429
|
+
}
|
|
3430
|
+
if (task.type === "Action") {
|
|
3431
|
+
const sleepMs = (_f = task == null ? void 0 : task.param) == null ? void 0 : _f.timeMs;
|
|
3432
|
+
const scrollType = (_g = task == null ? void 0 : task.param) == null ? void 0 : _g.scrollType;
|
|
3433
|
+
if (sleepMs) {
|
|
3434
|
+
value = `${sleepMs}ms`;
|
|
3435
|
+
} else if (scrollType) {
|
|
3436
|
+
const scrollDirection = (_h = task == null ? void 0 : task.param) == null ? void 0 : _h.direction;
|
|
3437
|
+
const scrollDistance = (_i = task == null ? void 0 : task.param) == null ? void 0 : _i.distance;
|
|
3438
|
+
value = `${scrollDirection || "down"}, ${scrollType || "once"}, ${scrollDistance || "distance-not-set"}`;
|
|
3439
|
+
} else {
|
|
3440
|
+
value = ((_j = task == null ? void 0 : task.param) == null ? void 0 : _j.value) || ((_k = task == null ? void 0 : task.param) == null ? void 0 : _k.scrollType);
|
|
3441
|
+
}
|
|
3442
|
+
if (!value) {
|
|
3443
|
+
value = task.thought;
|
|
3444
|
+
}
|
|
3445
|
+
}
|
|
3446
|
+
if (typeof value === "undefined")
|
|
3447
|
+
return "";
|
|
3448
|
+
return typeof value === "string" ? value : JSON.stringify(value, void 0, 2);
|
|
3449
|
+
}
|
|
3450
|
+
|
|
3399
3451
|
// src/common/tasks.ts
|
|
3400
3452
|
var PageTaskExecutor = class {
|
|
3401
3453
|
constructor(page, insight, opts) {
|
|
@@ -3530,6 +3582,7 @@ var PageTaskExecutor = class {
|
|
|
3530
3582
|
output: {
|
|
3531
3583
|
element
|
|
3532
3584
|
},
|
|
3585
|
+
pageContext,
|
|
3533
3586
|
log: {
|
|
3534
3587
|
dump: insightDump
|
|
3535
3588
|
},
|
|
@@ -3609,8 +3662,8 @@ var PageTaskExecutor = class {
|
|
|
3609
3662
|
thought: plan2.thought,
|
|
3610
3663
|
locate: plan2.locate,
|
|
3611
3664
|
executor: async (taskParam) => {
|
|
3612
|
-
|
|
3613
|
-
await this.page.keyboard.press(
|
|
3665
|
+
const keys = getKeyCommands(taskParam.value);
|
|
3666
|
+
await this.page.keyboard.press(keys);
|
|
3614
3667
|
}
|
|
3615
3668
|
};
|
|
3616
3669
|
tasks.push(taskActionKeyboardPress);
|
|
@@ -4018,7 +4071,7 @@ var PageTaskExecutor = class {
|
|
|
4018
4071
|
const cacheGroup = this.taskCache.getCacheGroupByPrompt(userPrompt);
|
|
4019
4072
|
const isCompleted = false;
|
|
4020
4073
|
let currentActionNumber = 0;
|
|
4021
|
-
const maxActionNumber =
|
|
4074
|
+
const maxActionNumber = 40;
|
|
4022
4075
|
while (!isCompleted && currentActionNumber < maxActionNumber) {
|
|
4023
4076
|
currentActionNumber++;
|
|
4024
4077
|
const planningTask = this.planningTaskToGoal(
|
|
@@ -4238,40 +4291,6 @@ var WebElementInfo = class {
|
|
|
4238
4291
|
}
|
|
4239
4292
|
};
|
|
4240
4293
|
|
|
4241
|
-
// src/common/ui-utils.ts
|
|
4242
|
-
function typeStr(task) {
|
|
4243
|
-
return task.subType ? `${task.type} / ${task.subType || ""}` : task.type;
|
|
4244
|
-
}
|
|
4245
|
-
function paramStr(task) {
|
|
4246
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
4247
|
-
let value;
|
|
4248
|
-
if (task.type === "Planning") {
|
|
4249
|
-
value = (_a = task == null ? void 0 : task.param) == null ? void 0 : _a.userPrompt;
|
|
4250
|
-
}
|
|
4251
|
-
if (task.type === "Insight") {
|
|
4252
|
-
value = ((_b = task == null ? void 0 : task.param) == null ? void 0 : _b.prompt) || ((_c = task == null ? void 0 : task.param) == null ? void 0 : _c.id) || ((_d = task == null ? void 0 : task.param) == null ? void 0 : _d.dataDemand) || ((_e = task == null ? void 0 : task.param) == null ? void 0 : _e.assertion);
|
|
4253
|
-
}
|
|
4254
|
-
if (task.type === "Action") {
|
|
4255
|
-
const sleepMs = (_f = task == null ? void 0 : task.param) == null ? void 0 : _f.timeMs;
|
|
4256
|
-
const scrollType = (_g = task == null ? void 0 : task.param) == null ? void 0 : _g.scrollType;
|
|
4257
|
-
if (sleepMs) {
|
|
4258
|
-
value = `${sleepMs}ms`;
|
|
4259
|
-
} else if (scrollType) {
|
|
4260
|
-
const scrollDirection = (_h = task == null ? void 0 : task.param) == null ? void 0 : _h.direction;
|
|
4261
|
-
const scrollDistance = (_i = task == null ? void 0 : task.param) == null ? void 0 : _i.distance;
|
|
4262
|
-
value = `${scrollDirection || "down"}, ${scrollType || "once"}, ${scrollDistance || "distance-not-set"}`;
|
|
4263
|
-
} else {
|
|
4264
|
-
value = ((_j = task == null ? void 0 : task.param) == null ? void 0 : _j.value) || ((_k = task == null ? void 0 : task.param) == null ? void 0 : _k.scrollType);
|
|
4265
|
-
}
|
|
4266
|
-
if (!value) {
|
|
4267
|
-
value = task.thought;
|
|
4268
|
-
}
|
|
4269
|
-
}
|
|
4270
|
-
if (typeof value === "undefined")
|
|
4271
|
-
return "";
|
|
4272
|
-
return typeof value === "string" ? value : JSON.stringify(value, void 0, 2);
|
|
4273
|
-
}
|
|
4274
|
-
|
|
4275
4294
|
// src/common/utils.ts
|
|
4276
4295
|
var import_node_assert4 = __toESM(require("assert"));
|
|
4277
4296
|
var import_node_fs3 = require("fs");
|
|
@@ -4607,7 +4626,7 @@ var Page = class {
|
|
|
4607
4626
|
get keyboard() {
|
|
4608
4627
|
return {
|
|
4609
4628
|
type: (text) => this.keyboardType(text),
|
|
4610
|
-
press: (
|
|
4629
|
+
press: (action) => this.keyboardPressAction(action)
|
|
4611
4630
|
};
|
|
4612
4631
|
}
|
|
4613
4632
|
async clearInput(element) {
|
|
@@ -4721,6 +4740,33 @@ var Page = class {
|
|
|
4721
4740
|
}
|
|
4722
4741
|
]);
|
|
4723
4742
|
}
|
|
4743
|
+
async keyboardPressAction(action) {
|
|
4744
|
+
if (Array.isArray(action)) {
|
|
4745
|
+
for (const act of action) {
|
|
4746
|
+
await this.browser.performActions([
|
|
4747
|
+
{
|
|
4748
|
+
type: "key",
|
|
4749
|
+
id: "keyboard",
|
|
4750
|
+
actions: [
|
|
4751
|
+
{ type: "keyDown", value: act.key },
|
|
4752
|
+
{ type: "keyUp", value: act.key }
|
|
4753
|
+
]
|
|
4754
|
+
}
|
|
4755
|
+
]);
|
|
4756
|
+
}
|
|
4757
|
+
} else {
|
|
4758
|
+
await this.browser.performActions([
|
|
4759
|
+
{
|
|
4760
|
+
type: "key",
|
|
4761
|
+
id: "keyboard",
|
|
4762
|
+
actions: [
|
|
4763
|
+
{ type: "keyDown", value: action.key },
|
|
4764
|
+
{ type: "keyUp", value: action.key }
|
|
4765
|
+
]
|
|
4766
|
+
}
|
|
4767
|
+
]);
|
|
4768
|
+
}
|
|
4769
|
+
}
|
|
4724
4770
|
async mouseClick(x, y, button = "left") {
|
|
4725
4771
|
await this.mouseMove(x, y);
|
|
4726
4772
|
await this.browser.performActions([
|
|
@@ -61,6 +61,33 @@ var import_node_assert4 = __toESM(require("assert"));
|
|
|
61
61
|
|
|
62
62
|
// src/chrome-extension/page.ts
|
|
63
63
|
var import_node_assert2 = __toESM(require("assert"));
|
|
64
|
+
|
|
65
|
+
// src/common/ui-utils.ts
|
|
66
|
+
var limitOpenNewTabScript = `
|
|
67
|
+
if (!window.__MIDSCENE_NEW_TAB_INTERCEPTOR_INITIALIZED__) {
|
|
68
|
+
window.__MIDSCENE_NEW_TAB_INTERCEPTOR_INITIALIZED__ = true;
|
|
69
|
+
|
|
70
|
+
// Intercept the window.open method (only once)
|
|
71
|
+
window.open = function(url) {
|
|
72
|
+
console.log('Blocked window.open:', url);
|
|
73
|
+
window.location.href = url;
|
|
74
|
+
return null;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// Block all a tag clicks with target="_blank" (only once)
|
|
78
|
+
document.addEventListener('click', function(e) {
|
|
79
|
+
const target = e.target.closest('a');
|
|
80
|
+
if (target && target.target === '_blank') {
|
|
81
|
+
e.preventDefault();
|
|
82
|
+
console.log('Blocked new tab:', target.href);
|
|
83
|
+
window.location.href = target.href;
|
|
84
|
+
target.removeAttribute('target');
|
|
85
|
+
}
|
|
86
|
+
}, true);
|
|
87
|
+
}
|
|
88
|
+
`;
|
|
89
|
+
|
|
90
|
+
// src/chrome-extension/page.ts
|
|
64
91
|
var import_extractor = require("@midscene/shared/extractor");
|
|
65
92
|
|
|
66
93
|
// src/chrome-extension/cdpInput.ts
|
|
@@ -262,9 +289,9 @@ function sleep(ms) {
|
|
|
262
289
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
263
290
|
}
|
|
264
291
|
var ChromeExtensionProxyPage = class {
|
|
265
|
-
constructor(
|
|
292
|
+
constructor(forceSameTabNavigation) {
|
|
266
293
|
this.pageType = "chrome-extension-proxy";
|
|
267
|
-
this.version = "0.11.
|
|
294
|
+
this.version = "0.11.3";
|
|
268
295
|
this.activeTabId = null;
|
|
269
296
|
this.tabIdOfDebuggerAttached = null;
|
|
270
297
|
this.attachingDebugger = null;
|
|
@@ -333,23 +360,24 @@ var ChromeExtensionProxyPage = class {
|
|
|
333
360
|
});
|
|
334
361
|
await cdpKeyboard.type(text, { delay: 0 });
|
|
335
362
|
},
|
|
336
|
-
press: async (
|
|
363
|
+
press: async (action) => {
|
|
337
364
|
const cdpKeyboard = new CdpKeyboard({
|
|
338
365
|
send: this.sendCommandToDebugger.bind(this)
|
|
339
366
|
});
|
|
340
|
-
const keys = Array.isArray(
|
|
367
|
+
const keys = Array.isArray(action) ? action : [action];
|
|
341
368
|
for (const k of keys) {
|
|
342
|
-
|
|
369
|
+
const commands = k.command ? [k.command] : [];
|
|
370
|
+
await cdpKeyboard.down(k.key, { commands });
|
|
343
371
|
}
|
|
344
372
|
for (const k of [...keys].reverse()) {
|
|
345
|
-
await cdpKeyboard.up(k);
|
|
373
|
+
await cdpKeyboard.up(k.key);
|
|
346
374
|
}
|
|
347
375
|
}
|
|
348
376
|
};
|
|
349
|
-
this.
|
|
377
|
+
this.forceSameTabNavigation = forceSameTabNavigation;
|
|
350
378
|
}
|
|
351
379
|
async getTabId() {
|
|
352
|
-
if (this.activeTabId && !this.
|
|
380
|
+
if (this.activeTabId && !this.forceSameTabNavigation) {
|
|
353
381
|
return this.activeTabId;
|
|
354
382
|
}
|
|
355
383
|
const tabId = await chrome.tabs.query({ active: true, currentWindow: true }).then((tabs) => {
|
|
@@ -436,6 +464,15 @@ var ChromeExtensionProxyPage = class {
|
|
|
436
464
|
this.tabIdOfDebuggerAttached = null;
|
|
437
465
|
}
|
|
438
466
|
async enableWaterFlowAnimation() {
|
|
467
|
+
if (this.forceSameTabNavigation) {
|
|
468
|
+
await chrome.debugger.sendCommand(
|
|
469
|
+
{ tabId: this.tabIdOfDebuggerAttached },
|
|
470
|
+
"Runtime.evaluate",
|
|
471
|
+
{
|
|
472
|
+
expression: limitOpenNewTabScript
|
|
473
|
+
}
|
|
474
|
+
);
|
|
475
|
+
}
|
|
439
476
|
const script = await injectWaterFlowAnimation();
|
|
440
477
|
await chrome.debugger.sendCommand(
|
|
441
478
|
{ tabId: this.tabIdOfDebuggerAttached },
|
|
@@ -622,7 +659,9 @@ var ChromeExtensionProxyPage = class {
|
|
|
622
659
|
commands: ["selectAll"]
|
|
623
660
|
});
|
|
624
661
|
await sleep(100);
|
|
625
|
-
await this.keyboard.press(
|
|
662
|
+
await this.keyboard.press({
|
|
663
|
+
key: "Backspace"
|
|
664
|
+
});
|
|
626
665
|
}
|
|
627
666
|
async destroy() {
|
|
628
667
|
this.activeTabId = null;
|
|
@@ -651,7 +690,7 @@ var BridgeClient = class {
|
|
|
651
690
|
this.socket = (0, import_socket.io)(this.endpoint, {
|
|
652
691
|
reconnection: false,
|
|
653
692
|
query: {
|
|
654
|
-
version: "0.11.
|
|
693
|
+
version: "0.11.3"
|
|
655
694
|
}
|
|
656
695
|
});
|
|
657
696
|
const timeout = setTimeout(() => {
|
|
@@ -710,8 +749,8 @@ ${(e == null ? void 0 : e.stack) || ""}`;
|
|
|
710
749
|
var ChromeExtensionPageBrowserSide = class extends ChromeExtensionProxyPage {
|
|
711
750
|
constructor(onDisconnect = () => {
|
|
712
751
|
}, onLogMessage = () => {
|
|
713
|
-
},
|
|
714
|
-
super(
|
|
752
|
+
}, forceSameTabNavigation = true) {
|
|
753
|
+
super(forceSameTabNavigation);
|
|
715
754
|
this.onDisconnect = onDisconnect;
|
|
716
755
|
this.onLogMessage = onLogMessage;
|
|
717
756
|
this.bridgeClient = null;
|
|
@@ -773,7 +812,7 @@ var ChromeExtensionPageBrowserSide = class extends ChromeExtensionProxyPage {
|
|
|
773
812
|
);
|
|
774
813
|
await this.bridgeClient.connect();
|
|
775
814
|
this.onLogMessage(
|
|
776
|
-
`Bridge connected, cli-side version v${this.bridgeClient.serverVersion}, browser-side version v${"0.11.
|
|
815
|
+
`Bridge connected, cli-side version v${this.bridgeClient.serverVersion}, browser-side version v${"0.11.3"}`,
|
|
777
816
|
"log"
|
|
778
817
|
);
|
|
779
818
|
}
|
|
@@ -781,18 +820,18 @@ var ChromeExtensionPageBrowserSide = class extends ChromeExtensionProxyPage {
|
|
|
781
820
|
return await this.setupBridgeClient();
|
|
782
821
|
}
|
|
783
822
|
async connectNewTabWithUrl(url, options = {
|
|
784
|
-
|
|
823
|
+
forceSameTabNavigation: true
|
|
785
824
|
}) {
|
|
786
825
|
const tab = await chrome.tabs.create({ url });
|
|
787
826
|
const tabId = tab.id;
|
|
788
827
|
(0, import_node_assert4.default)(tabId, "failed to get tabId after creating a new tab");
|
|
789
828
|
this.onLogMessage(`Creating new tab: ${url}`, "log");
|
|
790
|
-
if (options == null ? void 0 : options.
|
|
791
|
-
this.
|
|
829
|
+
if (options == null ? void 0 : options.forceSameTabNavigation) {
|
|
830
|
+
this.forceSameTabNavigation = true;
|
|
792
831
|
}
|
|
793
832
|
}
|
|
794
833
|
async connectCurrentTab(options = {
|
|
795
|
-
|
|
834
|
+
forceSameTabNavigation: true
|
|
796
835
|
}) {
|
|
797
836
|
var _a, _b;
|
|
798
837
|
const tabs = await chrome.tabs.query({ active: true, currentWindow: true });
|
|
@@ -800,8 +839,8 @@ var ChromeExtensionPageBrowserSide = class extends ChromeExtensionProxyPage {
|
|
|
800
839
|
const tabId = (_a = tabs[0]) == null ? void 0 : _a.id;
|
|
801
840
|
(0, import_node_assert4.default)(tabId, "failed to get tabId");
|
|
802
841
|
this.onLogMessage(`Connected to current tab: ${(_b = tabs[0]) == null ? void 0 : _b.url}`, "log");
|
|
803
|
-
if (options == null ? void 0 : options.
|
|
804
|
-
this.
|
|
842
|
+
if (options == null ? void 0 : options.forceSameTabNavigation) {
|
|
843
|
+
this.forceSameTabNavigation = true;
|
|
805
844
|
}
|
|
806
845
|
}
|
|
807
846
|
async destroy() {
|
package/dist/es/bridge-mode.js
CHANGED
|
@@ -3365,7 +3365,9 @@ var TaskCache = class {
|
|
|
3365
3365
|
if (!this.midscenePkgInfo) {
|
|
3366
3366
|
return void 0;
|
|
3367
3367
|
}
|
|
3368
|
-
|
|
3368
|
+
const jsonDataPkgVersion = jsonData.pkgVersion.split(".");
|
|
3369
|
+
const midscenePkgInfoPkgVersion = this.midscenePkgInfo.version.split(".");
|
|
3370
|
+
if (jsonDataPkgVersion[0] !== midscenePkgInfoPkgVersion[0] || jsonDataPkgVersion[1] !== midscenePkgInfoPkgVersion[1]) {
|
|
3369
3371
|
return void 0;
|
|
3370
3372
|
}
|
|
3371
3373
|
return jsonData;
|
|
@@ -3399,6 +3401,56 @@ var TaskCache = class {
|
|
|
3399
3401
|
}
|
|
3400
3402
|
};
|
|
3401
3403
|
|
|
3404
|
+
// src/common/ui-utils.ts
|
|
3405
|
+
function typeStr(task) {
|
|
3406
|
+
return task.subType ? `${task.type} / ${task.subType || ""}` : task.type;
|
|
3407
|
+
}
|
|
3408
|
+
function getKeyCommands(value) {
|
|
3409
|
+
const keys = Array.isArray(value) ? value : [value];
|
|
3410
|
+
return keys.reduce((acc, k) => {
|
|
3411
|
+
const includeMeta = keys.includes("Meta") || keys.includes("Control");
|
|
3412
|
+
if (includeMeta && (k === "a" || k === "A")) {
|
|
3413
|
+
return acc.concat([{ key: k, command: "SelectAll" }]);
|
|
3414
|
+
}
|
|
3415
|
+
if (includeMeta && (k === "c" || k === "C")) {
|
|
3416
|
+
return acc.concat([{ key: k, command: "Copy" }]);
|
|
3417
|
+
}
|
|
3418
|
+
if (includeMeta && (k === "v" || k === "V")) {
|
|
3419
|
+
return acc.concat([{ key: k, command: "Paste" }]);
|
|
3420
|
+
}
|
|
3421
|
+
return acc.concat([{ key: k }]);
|
|
3422
|
+
}, []);
|
|
3423
|
+
}
|
|
3424
|
+
function paramStr(task) {
|
|
3425
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
3426
|
+
let value;
|
|
3427
|
+
if (task.type === "Planning") {
|
|
3428
|
+
value = (_a = task == null ? void 0 : task.param) == null ? void 0 : _a.userPrompt;
|
|
3429
|
+
}
|
|
3430
|
+
if (task.type === "Insight") {
|
|
3431
|
+
value = ((_b = task == null ? void 0 : task.param) == null ? void 0 : _b.prompt) || ((_c = task == null ? void 0 : task.param) == null ? void 0 : _c.id) || ((_d = task == null ? void 0 : task.param) == null ? void 0 : _d.dataDemand) || ((_e = task == null ? void 0 : task.param) == null ? void 0 : _e.assertion);
|
|
3432
|
+
}
|
|
3433
|
+
if (task.type === "Action") {
|
|
3434
|
+
const sleepMs = (_f = task == null ? void 0 : task.param) == null ? void 0 : _f.timeMs;
|
|
3435
|
+
const scrollType = (_g = task == null ? void 0 : task.param) == null ? void 0 : _g.scrollType;
|
|
3436
|
+
if (sleepMs) {
|
|
3437
|
+
value = `${sleepMs}ms`;
|
|
3438
|
+
} else if (scrollType) {
|
|
3439
|
+
const scrollDirection = (_h = task == null ? void 0 : task.param) == null ? void 0 : _h.direction;
|
|
3440
|
+
const scrollDistance = (_i = task == null ? void 0 : task.param) == null ? void 0 : _i.distance;
|
|
3441
|
+
value = `${scrollDirection || "down"}, ${scrollType || "once"}, ${scrollDistance || "distance-not-set"}`;
|
|
3442
|
+
} else {
|
|
3443
|
+
value = ((_j = task == null ? void 0 : task.param) == null ? void 0 : _j.value) || ((_k = task == null ? void 0 : task.param) == null ? void 0 : _k.scrollType);
|
|
3444
|
+
}
|
|
3445
|
+
if (!value) {
|
|
3446
|
+
value = task.thought;
|
|
3447
|
+
}
|
|
3448
|
+
}
|
|
3449
|
+
if (typeof value === "undefined")
|
|
3450
|
+
return "";
|
|
3451
|
+
return typeof value === "string" ? value : JSON.stringify(value, void 0, 2);
|
|
3452
|
+
}
|
|
3453
|
+
|
|
3402
3454
|
// src/common/tasks.ts
|
|
3403
3455
|
var PageTaskExecutor = class {
|
|
3404
3456
|
constructor(page, insight, opts) {
|
|
@@ -3533,6 +3585,7 @@ var PageTaskExecutor = class {
|
|
|
3533
3585
|
output: {
|
|
3534
3586
|
element
|
|
3535
3587
|
},
|
|
3588
|
+
pageContext,
|
|
3536
3589
|
log: {
|
|
3537
3590
|
dump: insightDump
|
|
3538
3591
|
},
|
|
@@ -3612,8 +3665,8 @@ var PageTaskExecutor = class {
|
|
|
3612
3665
|
thought: plan2.thought,
|
|
3613
3666
|
locate: plan2.locate,
|
|
3614
3667
|
executor: async (taskParam) => {
|
|
3615
|
-
|
|
3616
|
-
await this.page.keyboard.press(
|
|
3668
|
+
const keys = getKeyCommands(taskParam.value);
|
|
3669
|
+
await this.page.keyboard.press(keys);
|
|
3617
3670
|
}
|
|
3618
3671
|
};
|
|
3619
3672
|
tasks.push(taskActionKeyboardPress);
|
|
@@ -4021,7 +4074,7 @@ var PageTaskExecutor = class {
|
|
|
4021
4074
|
const cacheGroup = this.taskCache.getCacheGroupByPrompt(userPrompt);
|
|
4022
4075
|
const isCompleted = false;
|
|
4023
4076
|
let currentActionNumber = 0;
|
|
4024
|
-
const maxActionNumber =
|
|
4077
|
+
const maxActionNumber = 40;
|
|
4025
4078
|
while (!isCompleted && currentActionNumber < maxActionNumber) {
|
|
4026
4079
|
currentActionNumber++;
|
|
4027
4080
|
const planningTask = this.planningTaskToGoal(
|
|
@@ -4241,40 +4294,6 @@ var WebElementInfo = class {
|
|
|
4241
4294
|
}
|
|
4242
4295
|
};
|
|
4243
4296
|
|
|
4244
|
-
// src/common/ui-utils.ts
|
|
4245
|
-
function typeStr(task) {
|
|
4246
|
-
return task.subType ? `${task.type} / ${task.subType || ""}` : task.type;
|
|
4247
|
-
}
|
|
4248
|
-
function paramStr(task) {
|
|
4249
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
4250
|
-
let value;
|
|
4251
|
-
if (task.type === "Planning") {
|
|
4252
|
-
value = (_a = task == null ? void 0 : task.param) == null ? void 0 : _a.userPrompt;
|
|
4253
|
-
}
|
|
4254
|
-
if (task.type === "Insight") {
|
|
4255
|
-
value = ((_b = task == null ? void 0 : task.param) == null ? void 0 : _b.prompt) || ((_c = task == null ? void 0 : task.param) == null ? void 0 : _c.id) || ((_d = task == null ? void 0 : task.param) == null ? void 0 : _d.dataDemand) || ((_e = task == null ? void 0 : task.param) == null ? void 0 : _e.assertion);
|
|
4256
|
-
}
|
|
4257
|
-
if (task.type === "Action") {
|
|
4258
|
-
const sleepMs = (_f = task == null ? void 0 : task.param) == null ? void 0 : _f.timeMs;
|
|
4259
|
-
const scrollType = (_g = task == null ? void 0 : task.param) == null ? void 0 : _g.scrollType;
|
|
4260
|
-
if (sleepMs) {
|
|
4261
|
-
value = `${sleepMs}ms`;
|
|
4262
|
-
} else if (scrollType) {
|
|
4263
|
-
const scrollDirection = (_h = task == null ? void 0 : task.param) == null ? void 0 : _h.direction;
|
|
4264
|
-
const scrollDistance = (_i = task == null ? void 0 : task.param) == null ? void 0 : _i.distance;
|
|
4265
|
-
value = `${scrollDirection || "down"}, ${scrollType || "once"}, ${scrollDistance || "distance-not-set"}`;
|
|
4266
|
-
} else {
|
|
4267
|
-
value = ((_j = task == null ? void 0 : task.param) == null ? void 0 : _j.value) || ((_k = task == null ? void 0 : task.param) == null ? void 0 : _k.scrollType);
|
|
4268
|
-
}
|
|
4269
|
-
if (!value) {
|
|
4270
|
-
value = task.thought;
|
|
4271
|
-
}
|
|
4272
|
-
}
|
|
4273
|
-
if (typeof value === "undefined")
|
|
4274
|
-
return "";
|
|
4275
|
-
return typeof value === "string" ? value : JSON.stringify(value, void 0, 2);
|
|
4276
|
-
}
|
|
4277
|
-
|
|
4278
4297
|
// src/common/utils.ts
|
|
4279
4298
|
var import_node_assert4 = __toESM(require("assert"));
|
|
4280
4299
|
var import_node_fs3 = require("fs");
|
|
@@ -4619,7 +4638,7 @@ var BridgeServer = class {
|
|
|
4619
4638
|
this.socket = socket;
|
|
4620
4639
|
const clientVersion = socket.handshake.query.version;
|
|
4621
4640
|
console.log(
|
|
4622
|
-
`Bridge connected, cli-side version v${"0.11.
|
|
4641
|
+
`Bridge connected, cli-side version v${"0.11.3"}, browser-side version v${clientVersion}`
|
|
4623
4642
|
);
|
|
4624
4643
|
socket.on("bridge-call-response" /* CallResponse */, (params) => {
|
|
4625
4644
|
const id = params.id;
|
|
@@ -4652,7 +4671,7 @@ var BridgeServer = class {
|
|
|
4652
4671
|
var _a;
|
|
4653
4672
|
(_a = this.onConnect) == null ? void 0 : _a.call(this);
|
|
4654
4673
|
const payload = {
|
|
4655
|
-
version: "0.11.
|
|
4674
|
+
version: "0.11.3"
|
|
4656
4675
|
};
|
|
4657
4676
|
socket.emit("bridge-connected" /* Connected */, payload);
|
|
4658
4677
|
Promise.resolve().then(() => {
|
|
@@ -4741,7 +4760,7 @@ var BridgeServer = class {
|
|
|
4741
4760
|
};
|
|
4742
4761
|
|
|
4743
4762
|
// src/bridge-mode/agent-cli-side.ts
|
|
4744
|
-
var
|
|
4763
|
+
var sleep3 = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
4745
4764
|
var getBridgePageInCliSide = () => {
|
|
4746
4765
|
const server = new BridgeServer(DefaultBridgeServerPort);
|
|
4747
4766
|
server.listen();
|
|
@@ -4819,11 +4838,11 @@ var AgentOverChromeBridge = class extends PageAgent {
|
|
|
4819
4838
|
}
|
|
4820
4839
|
async connectNewTabWithUrl(url, options) {
|
|
4821
4840
|
await this.page.connectNewTabWithUrl(url, options);
|
|
4822
|
-
await
|
|
4841
|
+
await sleep3(500);
|
|
4823
4842
|
}
|
|
4824
4843
|
async connectCurrentTab(options) {
|
|
4825
4844
|
await this.page.connectCurrentTab(options);
|
|
4826
|
-
await
|
|
4845
|
+
await sleep3(500);
|
|
4827
4846
|
}
|
|
4828
4847
|
async aiAction(prompt, options) {
|
|
4829
4848
|
if (options) {
|