@midscene/computer 1.8.6 → 1.8.7-beta-20260527113633.0
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/cli.mjs +221 -112
- package/dist/es/index.mjs +215 -106
- package/dist/es/mcp-server.mjs +221 -112
- package/dist/lib/cli.js +222 -113
- package/dist/lib/index.js +216 -107
- package/dist/lib/mcp-server.js +222 -113
- package/dist/types/index.d.ts +1 -0
- package/dist/types/mcp-server.d.ts +1 -0
- package/package.json +3 -3
package/dist/lib/cli.js
CHANGED
|
@@ -29,8 +29,6 @@ const cli_namespaceObject = require("@midscene/shared/cli");
|
|
|
29
29
|
const logger_namespaceObject = require("@midscene/shared/logger");
|
|
30
30
|
const base_tools_namespaceObject = require("@midscene/shared/mcp/base-tools");
|
|
31
31
|
const agent_namespaceObject = require("@midscene/core/agent");
|
|
32
|
-
const external_node_assert_namespaceObject = require("node:assert");
|
|
33
|
-
var external_node_assert_default = /*#__PURE__*/ __webpack_require__.n(external_node_assert_namespaceObject);
|
|
34
32
|
const external_node_child_process_namespaceObject = require("node:child_process");
|
|
35
33
|
const external_node_fs_namespaceObject = require("node:fs");
|
|
36
34
|
const external_node_module_namespaceObject = require("node:module");
|
|
@@ -41,6 +39,136 @@ const utils_namespaceObject = require("@midscene/core/utils");
|
|
|
41
39
|
const img_namespaceObject = require("@midscene/shared/img");
|
|
42
40
|
const external_screenshot_desktop_namespaceObject = require("screenshot-desktop");
|
|
43
41
|
var external_screenshot_desktop_default = /*#__PURE__*/ __webpack_require__.n(external_screenshot_desktop_namespaceObject);
|
|
42
|
+
const external_node_assert_namespaceObject = require("node:assert");
|
|
43
|
+
var external_node_assert_default = /*#__PURE__*/ __webpack_require__.n(external_node_assert_namespaceObject);
|
|
44
|
+
function _define_property(obj, key, value) {
|
|
45
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
46
|
+
value: value,
|
|
47
|
+
enumerable: true,
|
|
48
|
+
configurable: true,
|
|
49
|
+
writable: true
|
|
50
|
+
});
|
|
51
|
+
else obj[key] = value;
|
|
52
|
+
return obj;
|
|
53
|
+
}
|
|
54
|
+
class ComputerInputDriver {
|
|
55
|
+
destroy() {
|
|
56
|
+
if (this.destroyed) return;
|
|
57
|
+
this.destroyed = true;
|
|
58
|
+
this.rejectPendingInputDelays();
|
|
59
|
+
}
|
|
60
|
+
getScreenSize() {
|
|
61
|
+
return this.getLibnutOrThrow('getScreenSize').getScreenSize();
|
|
62
|
+
}
|
|
63
|
+
getMousePos() {
|
|
64
|
+
return this.getLibnutOrThrow('getMousePos').getMousePos();
|
|
65
|
+
}
|
|
66
|
+
moveMouse(x, y) {
|
|
67
|
+
this.getLibnutOrThrow('moveMouse').moveMouse(x, y);
|
|
68
|
+
}
|
|
69
|
+
mouseClick(button, double) {
|
|
70
|
+
const lib = this.getLibnutOrThrow('mouseClick');
|
|
71
|
+
if (void 0 !== double) lib.mouseClick(button, double);
|
|
72
|
+
else if (void 0 !== button) lib.mouseClick(button);
|
|
73
|
+
else lib.mouseClick();
|
|
74
|
+
}
|
|
75
|
+
mouseToggle(state, button = 'left') {
|
|
76
|
+
this.getLibnutOrThrow('mouseToggle').mouseToggle(state, button);
|
|
77
|
+
}
|
|
78
|
+
scrollMouse(x, y) {
|
|
79
|
+
this.getLibnutOrThrow('scrollMouse').scrollMouse(x, y);
|
|
80
|
+
}
|
|
81
|
+
keyTap(key, modifiers) {
|
|
82
|
+
const lib = this.getLibnutOrThrow('keyTap');
|
|
83
|
+
if (void 0 !== modifiers) lib.keyTap(key, modifiers);
|
|
84
|
+
else lib.keyTap(key);
|
|
85
|
+
}
|
|
86
|
+
sendKeyViaAppleScript(key, modifiers = []) {
|
|
87
|
+
this.assertActive('sendKeyViaAppleScript');
|
|
88
|
+
this.options.sendKeyViaAppleScript(key, modifiers);
|
|
89
|
+
}
|
|
90
|
+
sendKey(key, modifiers = []) {
|
|
91
|
+
if (this.options.useAppleScript()) return void this.sendKeyViaAppleScript(key, modifiers);
|
|
92
|
+
if (modifiers.length > 0) this.keyTap(key, modifiers);
|
|
93
|
+
else this.keyTap(key);
|
|
94
|
+
}
|
|
95
|
+
runPhasedScroll(direction, pixels, steps) {
|
|
96
|
+
this.assertActive('runPhasedScroll');
|
|
97
|
+
return this.options.runPhasedScroll(direction, pixels, steps);
|
|
98
|
+
}
|
|
99
|
+
async delay(ms) {
|
|
100
|
+
this.assertActive('delay');
|
|
101
|
+
return new Promise((resolve, reject)=>{
|
|
102
|
+
const waitRef = {
|
|
103
|
+
timeoutId: setTimeout(()=>{
|
|
104
|
+
this.pendingInputDelayWaits.delete(waitRef);
|
|
105
|
+
try {
|
|
106
|
+
this.assertActive('delay');
|
|
107
|
+
resolve();
|
|
108
|
+
} catch (error) {
|
|
109
|
+
reject(error);
|
|
110
|
+
}
|
|
111
|
+
}, ms),
|
|
112
|
+
reject
|
|
113
|
+
};
|
|
114
|
+
this.pendingInputDelayWaits.add(waitRef);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
async smoothMoveMouse(targetX, targetY, steps, stepDelay) {
|
|
118
|
+
const currentPos = this.getMousePos();
|
|
119
|
+
for(let i = 1; i <= steps; i++){
|
|
120
|
+
const stepX = Math.round(currentPos.x + (targetX - currentPos.x) * i / steps);
|
|
121
|
+
const stepY = Math.round(currentPos.y + (targetY - currentPos.y) * i / steps);
|
|
122
|
+
this.moveMouse(stepX, stepY);
|
|
123
|
+
await this.delay(stepDelay);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
async withMouseButton(button, run) {
|
|
127
|
+
this.mouseToggle('down', button);
|
|
128
|
+
try {
|
|
129
|
+
return await run();
|
|
130
|
+
} finally{
|
|
131
|
+
this.releaseMouseButton(button);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
getLibnutOrThrow(methodName) {
|
|
135
|
+
this.assertActive(methodName);
|
|
136
|
+
const libnut = this.options.getLibnut();
|
|
137
|
+
external_node_assert_default()(libnut, 'libnut not initialized');
|
|
138
|
+
return libnut;
|
|
139
|
+
}
|
|
140
|
+
assertActive(methodName) {
|
|
141
|
+
if (this.destroyed) throw this.createDestroyedError(methodName);
|
|
142
|
+
}
|
|
143
|
+
createDestroyedError(methodName) {
|
|
144
|
+
return new Error(`ComputerDevice has been destroyed (cannot run ${methodName})`);
|
|
145
|
+
}
|
|
146
|
+
releaseMouseButton(button) {
|
|
147
|
+
try {
|
|
148
|
+
const libnut = this.options.getLibnut();
|
|
149
|
+
external_node_assert_default()(libnut, 'libnut not initialized');
|
|
150
|
+
libnut.mouseToggle('up', button);
|
|
151
|
+
} catch (error) {
|
|
152
|
+
this.options.debug(`Failed to release mouse button ${button}: ${error}`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
rejectPendingInputDelays() {
|
|
156
|
+
const error = this.createDestroyedError('in-flight input');
|
|
157
|
+
for (const waitRef of this.pendingInputDelayWaits){
|
|
158
|
+
clearTimeout(waitRef.timeoutId);
|
|
159
|
+
waitRef.reject(error);
|
|
160
|
+
}
|
|
161
|
+
this.pendingInputDelayWaits.clear();
|
|
162
|
+
}
|
|
163
|
+
constructor(options){
|
|
164
|
+
_define_property(this, "options", void 0);
|
|
165
|
+
_define_property(this, "destroyed", void 0);
|
|
166
|
+
_define_property(this, "pendingInputDelayWaits", void 0);
|
|
167
|
+
this.options = options;
|
|
168
|
+
this.destroyed = false;
|
|
169
|
+
this.pendingInputDelayWaits = new Set();
|
|
170
|
+
}
|
|
171
|
+
}
|
|
44
172
|
const debugXvfb = (0, logger_namespaceObject.getDebug)('computer:xvfb');
|
|
45
173
|
function checkXvfbInstalled() {
|
|
46
174
|
try {
|
|
@@ -108,7 +236,7 @@ function needsXvfb(explicitOpt) {
|
|
|
108
236
|
if ('linux' !== process.platform) return false;
|
|
109
237
|
return true === explicitOpt;
|
|
110
238
|
}
|
|
111
|
-
function
|
|
239
|
+
function device_define_property(obj, key, value) {
|
|
112
240
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
113
241
|
value: value,
|
|
114
242
|
enumerable: true,
|
|
@@ -229,17 +357,17 @@ function sendKeyViaAppleScript(key, modifiers = []) {
|
|
|
229
357
|
script
|
|
230
358
|
]);
|
|
231
359
|
}
|
|
232
|
-
let
|
|
360
|
+
let device_libnut = null;
|
|
233
361
|
let libnutLoadError = null;
|
|
234
362
|
async function getLibnut() {
|
|
235
|
-
if (
|
|
363
|
+
if (device_libnut) return device_libnut;
|
|
236
364
|
if (libnutLoadError) throw libnutLoadError;
|
|
237
365
|
try {
|
|
238
366
|
const require1 = (0, external_node_module_namespaceObject.createRequire)(__rslib_import_meta_url__);
|
|
239
367
|
const libnutModule = require1('@computer-use/libnut/dist/import_libnut');
|
|
240
|
-
|
|
241
|
-
if (!
|
|
242
|
-
return
|
|
368
|
+
device_libnut = libnutModule.libnut;
|
|
369
|
+
if (!device_libnut) throw new Error('libnut module loaded but libnut object is undefined');
|
|
370
|
+
return device_libnut;
|
|
243
371
|
} catch (error) {
|
|
244
372
|
libnutLoadError = error;
|
|
245
373
|
throw new Error(`Failed to load @computer-use/libnut. Make sure it is properly installed and compiled for your platform. Error: ${error}`);
|
|
@@ -309,16 +437,6 @@ function runPhasedScroll(direction, pixels, steps) {
|
|
|
309
437
|
return false;
|
|
310
438
|
}
|
|
311
439
|
}
|
|
312
|
-
async function smoothMoveMouse(targetX, targetY, steps, stepDelay) {
|
|
313
|
-
external_node_assert_default()(libnut, 'libnut not initialized');
|
|
314
|
-
const currentPos = libnut.getMousePos();
|
|
315
|
-
for(let i = 1; i <= steps; i++){
|
|
316
|
-
const stepX = Math.round(currentPos.x + (targetX - currentPos.x) * i / steps);
|
|
317
|
-
const stepY = Math.round(currentPos.y + (targetY - currentPos.y) * i / steps);
|
|
318
|
-
libnut.moveMouse(stepX, stepY);
|
|
319
|
-
await (0, utils_namespaceObject.sleep)(stepDelay);
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
440
|
const KEY_NAME_MAP = {
|
|
323
441
|
windows: 'win',
|
|
324
442
|
win: 'win',
|
|
@@ -404,7 +522,7 @@ class ComputerDevice {
|
|
|
404
522
|
process.on('SIGINT', this.xvfbCleanup);
|
|
405
523
|
process.on('SIGTERM', this.xvfbCleanup);
|
|
406
524
|
}
|
|
407
|
-
|
|
525
|
+
device_libnut = await getLibnut();
|
|
408
526
|
const size = await this.size();
|
|
409
527
|
const displays = await ComputerDevice.listDisplays();
|
|
410
528
|
const headlessInfo = this.xvfbInstance ? `\nHeadless: true (Xvfb on ${this.xvfbInstance.display})` : '';
|
|
@@ -428,7 +546,7 @@ Available Displays: ${displays.length > 0 ? displays.map((d)=>d.name).join(', ')
|
|
|
428
546
|
}
|
|
429
547
|
async healthCheck() {
|
|
430
548
|
console.log('[HealthCheck] Starting health check...');
|
|
431
|
-
console.log("[HealthCheck] @midscene/computer v1.8.
|
|
549
|
+
console.log("[HealthCheck] @midscene/computer v1.8.7-beta-20260527113633.0");
|
|
432
550
|
console.log('[HealthCheck] Taking screenshot...');
|
|
433
551
|
const screenshotTimeout = 15000;
|
|
434
552
|
let timeoutId;
|
|
@@ -441,17 +559,16 @@ Available Displays: ${displays.length > 0 ? displays.map((d)=>d.name).join(', ')
|
|
|
441
559
|
]);
|
|
442
560
|
console.log(`[HealthCheck] Screenshot succeeded (length=${base64.length})`);
|
|
443
561
|
console.log('[HealthCheck] Moving mouse...');
|
|
444
|
-
|
|
445
|
-
const startPos = libnut.getMousePos();
|
|
562
|
+
const startPos = this.inputDriver.getMousePos();
|
|
446
563
|
console.log(`[HealthCheck] Current mouse position: (${startPos.x}, ${startPos.y})`);
|
|
447
564
|
const offsetX = Math.floor(40 * Math.random()) + 10;
|
|
448
565
|
const offsetY = Math.floor(40 * Math.random()) + 10;
|
|
449
566
|
const targetX = startPos.x + offsetX;
|
|
450
567
|
const targetY = startPos.y + offsetY;
|
|
451
568
|
console.log(`[HealthCheck] Moving mouse to (${targetX}, ${targetY})...`);
|
|
452
|
-
|
|
569
|
+
this.inputDriver.moveMouse(targetX, targetY);
|
|
453
570
|
await (0, utils_namespaceObject.sleep)(50);
|
|
454
|
-
const movedPos =
|
|
571
|
+
const movedPos = this.inputDriver.getMousePos();
|
|
455
572
|
console.log(`[HealthCheck] Mouse position after move: (${movedPos.x}, ${movedPos.y})`);
|
|
456
573
|
const deltaX = Math.abs(movedPos.x - targetX);
|
|
457
574
|
const deltaY = Math.abs(movedPos.y - targetY);
|
|
@@ -465,7 +582,7 @@ Available Displays: ${displays.length > 0 ? displays.map((d)=>d.name).join(', ')
|
|
|
465
582
|
debugDevice(hint);
|
|
466
583
|
}
|
|
467
584
|
}
|
|
468
|
-
|
|
585
|
+
this.inputDriver.moveMouse(startPos.x, startPos.y);
|
|
469
586
|
console.log(`[HealthCheck] Mouse restored to (${startPos.x}, ${startPos.y})`);
|
|
470
587
|
console.log('[HealthCheck] Listing monitors...');
|
|
471
588
|
const displays = await ComputerDevice.listDisplays();
|
|
@@ -528,9 +645,8 @@ Original error: ${lastRawMessage}`);
|
|
|
528
645
|
throw new Error(`Failed to take screenshot: ${lastRawMessage}`);
|
|
529
646
|
}
|
|
530
647
|
async size() {
|
|
531
|
-
external_node_assert_default()(libnut, 'libnut not initialized');
|
|
532
648
|
try {
|
|
533
|
-
const screenSize =
|
|
649
|
+
const screenSize = this.inputDriver.getScreenSize();
|
|
534
650
|
return {
|
|
535
651
|
width: screenSize.width,
|
|
536
652
|
height: screenSize.height
|
|
@@ -541,7 +657,6 @@ Original error: ${lastRawMessage}`);
|
|
|
541
657
|
}
|
|
542
658
|
}
|
|
543
659
|
async typeViaClipboard(text) {
|
|
544
|
-
external_node_assert_default()(libnut, 'libnut not initialized');
|
|
545
660
|
debugDevice('Using clipboard to input text', {
|
|
546
661
|
textLength: text.length,
|
|
547
662
|
preview: text.substring(0, 20)
|
|
@@ -550,17 +665,17 @@ Original error: ${lastRawMessage}`);
|
|
|
550
665
|
const oldClipboard = await clipboardy.default.read().catch(()=>'');
|
|
551
666
|
try {
|
|
552
667
|
await clipboardy.default.write(text);
|
|
553
|
-
await
|
|
554
|
-
if (this.useAppleScript) sendKeyViaAppleScript('v', [
|
|
668
|
+
await this.inputDriver.delay(50);
|
|
669
|
+
if (this.useAppleScript) this.inputDriver.sendKeyViaAppleScript('v', [
|
|
555
670
|
'command'
|
|
556
671
|
]);
|
|
557
672
|
else {
|
|
558
673
|
const modifier = 'darwin' === process.platform ? 'command' : 'control';
|
|
559
|
-
|
|
674
|
+
this.inputDriver.keyTap('v', [
|
|
560
675
|
modifier
|
|
561
676
|
]);
|
|
562
677
|
}
|
|
563
|
-
await
|
|
678
|
+
await this.inputDriver.delay(100);
|
|
564
679
|
} finally{
|
|
565
680
|
if (oldClipboard) await clipboardy.default.write(oldClipboard).catch(()=>{
|
|
566
681
|
debugDevice('Failed to restore clipboard content');
|
|
@@ -568,28 +683,25 @@ Original error: ${lastRawMessage}`);
|
|
|
568
683
|
}
|
|
569
684
|
}
|
|
570
685
|
async smartTypeString(text) {
|
|
571
|
-
external_node_assert_default()(libnut, 'libnut not initialized');
|
|
572
686
|
await this.typeViaClipboard(text);
|
|
573
687
|
}
|
|
574
688
|
async selectAllAndDelete() {
|
|
575
|
-
external_node_assert_default()(libnut, 'libnut not initialized');
|
|
576
689
|
if (this.useAppleScript) {
|
|
577
|
-
sendKeyViaAppleScript('a', [
|
|
690
|
+
this.inputDriver.sendKeyViaAppleScript('a', [
|
|
578
691
|
'command'
|
|
579
692
|
]);
|
|
580
|
-
await
|
|
581
|
-
sendKeyViaAppleScript('backspace', []);
|
|
693
|
+
await this.inputDriver.delay(50);
|
|
694
|
+
this.inputDriver.sendKeyViaAppleScript('backspace', []);
|
|
582
695
|
return;
|
|
583
696
|
}
|
|
584
697
|
const modifier = 'darwin' === process.platform ? 'command' : 'control';
|
|
585
|
-
|
|
698
|
+
this.inputDriver.keyTap('a', [
|
|
586
699
|
modifier
|
|
587
700
|
]);
|
|
588
|
-
await
|
|
589
|
-
|
|
701
|
+
await this.inputDriver.delay(50);
|
|
702
|
+
this.inputDriver.keyTap('backspace');
|
|
590
703
|
}
|
|
591
704
|
async pressKeyboardShortcut(keyName) {
|
|
592
|
-
external_node_assert_default()(libnut, 'libnut not initialized');
|
|
593
705
|
const keys = keyName.split('+');
|
|
594
706
|
const modifiers = keys.slice(0, -1).map(normalizeKeyName);
|
|
595
707
|
const key = normalizePrimaryKey(keys[keys.length - 1]);
|
|
@@ -599,30 +711,27 @@ Original error: ${lastRawMessage}`);
|
|
|
599
711
|
modifiers,
|
|
600
712
|
driver: this.useAppleScript ? "applescript" : 'libnut'
|
|
601
713
|
});
|
|
602
|
-
|
|
603
|
-
else if (modifiers.length > 0) libnut.keyTap(key, modifiers);
|
|
604
|
-
else libnut.keyTap(key);
|
|
714
|
+
this.inputDriver.sendKey(key, modifiers);
|
|
605
715
|
}
|
|
606
716
|
async performScroll(param) {
|
|
607
|
-
external_node_assert_default()(libnut, 'libnut not initialized');
|
|
608
717
|
if (param.locate) {
|
|
609
718
|
const element = param.locate;
|
|
610
719
|
const [x, y] = element.center;
|
|
611
|
-
|
|
720
|
+
this.inputDriver.moveMouse(Math.round(x), Math.round(y));
|
|
612
721
|
}
|
|
613
722
|
const scrollType = param?.scrollType;
|
|
614
723
|
const edgeSpec = scrollType && scrollType in EDGE_SCROLL_SPEC ? EDGE_SCROLL_SPEC[scrollType] : null;
|
|
615
724
|
if (edgeSpec) {
|
|
616
|
-
if (runPhasedScroll(edgeSpec.direction, EDGE_SCROLL_TOTAL_PX, EDGE_SCROLL_STEPS)) return void await
|
|
725
|
+
if (this.inputDriver.runPhasedScroll(edgeSpec.direction, EDGE_SCROLL_TOTAL_PX, EDGE_SCROLL_STEPS)) return void await this.inputDriver.delay(SCROLL_COMPLETE_DELAY);
|
|
617
726
|
if (this.useAppleScript) {
|
|
618
|
-
sendKeyViaAppleScript(edgeSpec.key);
|
|
619
|
-
await
|
|
727
|
+
this.inputDriver.sendKeyViaAppleScript(edgeSpec.key);
|
|
728
|
+
await this.inputDriver.delay(SCROLL_COMPLETE_DELAY);
|
|
620
729
|
return;
|
|
621
730
|
}
|
|
622
731
|
const [dx, dy] = edgeSpec.libnut;
|
|
623
732
|
for(let i = 0; i < SCROLL_REPEAT_COUNT; i++){
|
|
624
|
-
|
|
625
|
-
await
|
|
733
|
+
this.inputDriver.scrollMouse(dx, dy);
|
|
734
|
+
await this.inputDriver.delay(SCROLL_STEP_DELAY);
|
|
626
735
|
}
|
|
627
736
|
return;
|
|
628
737
|
}
|
|
@@ -639,17 +748,17 @@ Original error: ${lastRawMessage}`);
|
|
|
639
748
|
}
|
|
640
749
|
if (isKnownDirection) {
|
|
641
750
|
const steps = Math.max(PHASED_MIN_STEPS, Math.round(distance / PHASED_PIXELS_PER_STEP));
|
|
642
|
-
if (runPhasedScroll(direction, distance, steps)) return void await
|
|
751
|
+
if (this.inputDriver.runPhasedScroll(direction, distance, steps)) return void await this.inputDriver.delay(SCROLL_COMPLETE_DELAY);
|
|
643
752
|
}
|
|
644
753
|
if (this.useAppleScript && ('up' === direction || 'down' === direction)) {
|
|
645
754
|
if (!screenSize) screenSize = await this.size();
|
|
646
755
|
const pages = Math.max(1, Math.round(distance / screenSize.height));
|
|
647
756
|
const key = 'up' === direction ? 'pageup' : 'pagedown';
|
|
648
757
|
for(let i = 0; i < pages; i++){
|
|
649
|
-
sendKeyViaAppleScript(key);
|
|
650
|
-
await
|
|
758
|
+
this.inputDriver.sendKeyViaAppleScript(key);
|
|
759
|
+
await this.inputDriver.delay(SCROLL_STEP_DELAY);
|
|
651
760
|
}
|
|
652
|
-
await
|
|
761
|
+
await this.inputDriver.delay(SCROLL_COMPLETE_DELAY);
|
|
653
762
|
return;
|
|
654
763
|
}
|
|
655
764
|
const ticks = Math.ceil(distance / 100);
|
|
@@ -675,8 +784,8 @@ Original error: ${lastRawMessage}`);
|
|
|
675
784
|
0,
|
|
676
785
|
-ticks
|
|
677
786
|
];
|
|
678
|
-
|
|
679
|
-
await
|
|
787
|
+
this.inputDriver.scrollMouse(dx, dy);
|
|
788
|
+
await this.inputDriver.delay(SCROLL_COMPLETE_DELAY);
|
|
680
789
|
return;
|
|
681
790
|
}
|
|
682
791
|
throw new Error(`Unknown scroll type: ${scrollType}, param: ${JSON.stringify(param)}`);
|
|
@@ -695,6 +804,8 @@ Original error: ${lastRawMessage}`);
|
|
|
695
804
|
}
|
|
696
805
|
async destroy() {
|
|
697
806
|
if (this.destroyed) return;
|
|
807
|
+
this.destroyed = true;
|
|
808
|
+
this.inputDriver.destroy();
|
|
698
809
|
if (this.xvfbInstance) {
|
|
699
810
|
this.xvfbInstance.stop();
|
|
700
811
|
this.xvfbInstance = void 0;
|
|
@@ -705,96 +816,94 @@ Original error: ${lastRawMessage}`);
|
|
|
705
816
|
process.removeListener('SIGTERM', this.xvfbCleanup);
|
|
706
817
|
this.xvfbCleanup = void 0;
|
|
707
818
|
}
|
|
708
|
-
this.destroyed = true;
|
|
709
819
|
debugDevice('Computer device destroyed');
|
|
710
820
|
}
|
|
711
821
|
async url() {
|
|
712
822
|
return '';
|
|
713
823
|
}
|
|
714
824
|
constructor(options){
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
825
|
+
device_define_property(this, "interfaceType", 'computer');
|
|
826
|
+
device_define_property(this, "options", void 0);
|
|
827
|
+
device_define_property(this, "displayId", void 0);
|
|
828
|
+
device_define_property(this, "description", void 0);
|
|
829
|
+
device_define_property(this, "destroyed", false);
|
|
830
|
+
device_define_property(this, "xvfbInstance", void 0);
|
|
831
|
+
device_define_property(this, "xvfbCleanup", void 0);
|
|
832
|
+
device_define_property(this, "inputDriver", new ComputerInputDriver({
|
|
833
|
+
getLibnut: ()=>device_libnut,
|
|
834
|
+
useAppleScript: ()=>this.useAppleScript,
|
|
835
|
+
sendKeyViaAppleScript,
|
|
836
|
+
runPhasedScroll,
|
|
837
|
+
debug: (message)=>debugDevice(message)
|
|
838
|
+
}));
|
|
839
|
+
device_define_property(this, "useAppleScript", void 0);
|
|
840
|
+
device_define_property(this, "uri", void 0);
|
|
841
|
+
device_define_property(this, "inputPrimitives", {
|
|
725
842
|
pointer: {
|
|
726
843
|
tap: async ({ x, y })=>{
|
|
727
|
-
external_node_assert_default()(libnut, 'libnut not initialized');
|
|
728
844
|
const targetX = Math.round(x);
|
|
729
845
|
const targetY = Math.round(y);
|
|
730
|
-
await smoothMoveMouse(targetX, targetY, SMOOTH_MOVE_STEPS_TAP, SMOOTH_MOVE_DELAY_TAP);
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
846
|
+
await this.inputDriver.smoothMoveMouse(targetX, targetY, SMOOTH_MOVE_STEPS_TAP, SMOOTH_MOVE_DELAY_TAP);
|
|
847
|
+
await this.inputDriver.withMouseButton('left', async ()=>{
|
|
848
|
+
await this.inputDriver.delay(CLICK_HOLD_DURATION);
|
|
849
|
+
});
|
|
734
850
|
},
|
|
735
851
|
doubleClick: async ({ x, y })=>{
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
libnut.mouseClick('left', true);
|
|
852
|
+
this.inputDriver.moveMouse(Math.round(x), Math.round(y));
|
|
853
|
+
this.inputDriver.mouseClick('left', true);
|
|
739
854
|
},
|
|
740
855
|
rightClick: async ({ x, y })=>{
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
libnut.mouseClick('right');
|
|
856
|
+
this.inputDriver.moveMouse(Math.round(x), Math.round(y));
|
|
857
|
+
this.inputDriver.mouseClick('right');
|
|
744
858
|
},
|
|
745
859
|
hover: async ({ x, y })=>{
|
|
746
|
-
|
|
747
|
-
await
|
|
748
|
-
await (0, utils_namespaceObject.sleep)(MOUSE_MOVE_EFFECT_WAIT);
|
|
860
|
+
await this.inputDriver.smoothMoveMouse(Math.round(x), Math.round(y), SMOOTH_MOVE_STEPS_MOUSE_MOVE, SMOOTH_MOVE_DELAY_MOUSE_MOVE);
|
|
861
|
+
await this.inputDriver.delay(MOUSE_MOVE_EFFECT_WAIT);
|
|
749
862
|
},
|
|
750
863
|
dragAndDrop: async (from, to)=>{
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
libnut.mouseToggle('up', 'left');
|
|
864
|
+
this.inputDriver.moveMouse(Math.round(from.x), Math.round(from.y));
|
|
865
|
+
await this.inputDriver.withMouseButton('left', async ()=>{
|
|
866
|
+
await this.inputDriver.delay(100);
|
|
867
|
+
this.inputDriver.moveMouse(Math.round(to.x), Math.round(to.y));
|
|
868
|
+
await this.inputDriver.delay(100);
|
|
869
|
+
});
|
|
758
870
|
}
|
|
759
871
|
},
|
|
760
872
|
keyboard: {
|
|
761
873
|
typeText: async (value, opts)=>{
|
|
762
|
-
external_node_assert_default()(libnut, 'libnut not initialized');
|
|
763
874
|
const element = opts?.target;
|
|
764
875
|
if (element) {
|
|
765
876
|
const [x, y] = element.center;
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
await
|
|
877
|
+
this.inputDriver.moveMouse(Math.round(x), Math.round(y));
|
|
878
|
+
this.inputDriver.mouseClick('left');
|
|
879
|
+
await this.inputDriver.delay(INPUT_FOCUS_DELAY);
|
|
769
880
|
if (opts?.replace !== false) {
|
|
770
881
|
await this.selectAllAndDelete();
|
|
771
|
-
await
|
|
882
|
+
await this.inputDriver.delay(INPUT_CLEAR_DELAY);
|
|
772
883
|
}
|
|
773
884
|
}
|
|
774
885
|
await this.smartTypeString(value);
|
|
775
886
|
},
|
|
776
887
|
keyboardPress: async (keyName, opts)=>{
|
|
777
|
-
external_node_assert_default()(libnut, 'libnut not initialized');
|
|
778
888
|
const target = opts?.target;
|
|
779
889
|
if (target) {
|
|
780
890
|
const [x, y] = target.center;
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
await
|
|
891
|
+
this.inputDriver.moveMouse(Math.round(x), Math.round(y));
|
|
892
|
+
this.inputDriver.mouseClick('left');
|
|
893
|
+
await this.inputDriver.delay(50);
|
|
784
894
|
}
|
|
785
895
|
await this.pressKeyboardShortcut(keyName);
|
|
786
896
|
},
|
|
787
897
|
clearInput: async (target)=>{
|
|
788
|
-
external_node_assert_default()(libnut, 'libnut not initialized');
|
|
789
898
|
if (target) {
|
|
790
899
|
const element = target;
|
|
791
900
|
const [x, y] = element.center;
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
await
|
|
901
|
+
this.inputDriver.moveMouse(Math.round(x), Math.round(y));
|
|
902
|
+
this.inputDriver.mouseClick('left');
|
|
903
|
+
await this.inputDriver.delay(100);
|
|
795
904
|
}
|
|
796
905
|
await this.selectAllAndDelete();
|
|
797
|
-
await
|
|
906
|
+
await this.inputDriver.delay(50);
|
|
798
907
|
}
|
|
799
908
|
},
|
|
800
909
|
scroll: {
|
|
@@ -1115,7 +1224,7 @@ class HelperProcessRDPBackendClient {
|
|
|
1115
1224
|
function createDefaultRDPBackendClient() {
|
|
1116
1225
|
return new HelperProcessRDPBackendClient();
|
|
1117
1226
|
}
|
|
1118
|
-
function
|
|
1227
|
+
function rdp_device_define_property(obj, key, value) {
|
|
1119
1228
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
1120
1229
|
value: value,
|
|
1121
1230
|
enumerable: true,
|
|
@@ -1274,14 +1383,14 @@ class RDPDevice {
|
|
|
1274
1383
|
}
|
|
1275
1384
|
}
|
|
1276
1385
|
constructor(options){
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1386
|
+
rdp_device_define_property(this, "interfaceType", 'rdp');
|
|
1387
|
+
rdp_device_define_property(this, "options", void 0);
|
|
1388
|
+
rdp_device_define_property(this, "backend", void 0);
|
|
1389
|
+
rdp_device_define_property(this, "connectionInfo", void 0);
|
|
1390
|
+
rdp_device_define_property(this, "destroyed", false);
|
|
1391
|
+
rdp_device_define_property(this, "cursorPosition", void 0);
|
|
1392
|
+
rdp_device_define_property(this, "uri", void 0);
|
|
1393
|
+
rdp_device_define_property(this, "inputPrimitives", {
|
|
1285
1394
|
pointer: {
|
|
1286
1395
|
tap: async ({ x, y })=>{
|
|
1287
1396
|
await this.movePointer(Math.round(x), Math.round(y), {
|
|
@@ -1615,7 +1724,7 @@ class ComputerMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
|
|
|
1615
1724
|
const tools = new ComputerMidsceneTools();
|
|
1616
1725
|
(0, cli_namespaceObject.runToolsCLI)(tools, 'midscene-computer', {
|
|
1617
1726
|
stripPrefix: 'computer_',
|
|
1618
|
-
version: "1.8.
|
|
1727
|
+
version: "1.8.7-beta-20260527113633.0",
|
|
1619
1728
|
extraCommands: (0, core_namespaceObject.createReportCliCommands)()
|
|
1620
1729
|
}).catch((e)=>{
|
|
1621
1730
|
process.exit((0, cli_namespaceObject.reportCLIError)(e));
|