@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/index.js
CHANGED
|
@@ -55,8 +55,6 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
55
55
|
ComputerDevice: ()=>ComputerDevice,
|
|
56
56
|
ComputerAgent: ()=>ComputerAgent
|
|
57
57
|
});
|
|
58
|
-
const external_node_assert_namespaceObject = require("node:assert");
|
|
59
|
-
var external_node_assert_default = /*#__PURE__*/ __webpack_require__.n(external_node_assert_namespaceObject);
|
|
60
58
|
const external_node_child_process_namespaceObject = require("node:child_process");
|
|
61
59
|
const external_node_fs_namespaceObject = require("node:fs");
|
|
62
60
|
const external_node_module_namespaceObject = require("node:module");
|
|
@@ -68,6 +66,136 @@ const img_namespaceObject = require("@midscene/shared/img");
|
|
|
68
66
|
const logger_namespaceObject = require("@midscene/shared/logger");
|
|
69
67
|
const external_screenshot_desktop_namespaceObject = require("screenshot-desktop");
|
|
70
68
|
var external_screenshot_desktop_default = /*#__PURE__*/ __webpack_require__.n(external_screenshot_desktop_namespaceObject);
|
|
69
|
+
const external_node_assert_namespaceObject = require("node:assert");
|
|
70
|
+
var external_node_assert_default = /*#__PURE__*/ __webpack_require__.n(external_node_assert_namespaceObject);
|
|
71
|
+
function _define_property(obj, key, value) {
|
|
72
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
73
|
+
value: value,
|
|
74
|
+
enumerable: true,
|
|
75
|
+
configurable: true,
|
|
76
|
+
writable: true
|
|
77
|
+
});
|
|
78
|
+
else obj[key] = value;
|
|
79
|
+
return obj;
|
|
80
|
+
}
|
|
81
|
+
class ComputerInputDriver {
|
|
82
|
+
destroy() {
|
|
83
|
+
if (this.destroyed) return;
|
|
84
|
+
this.destroyed = true;
|
|
85
|
+
this.rejectPendingInputDelays();
|
|
86
|
+
}
|
|
87
|
+
getScreenSize() {
|
|
88
|
+
return this.getLibnutOrThrow('getScreenSize').getScreenSize();
|
|
89
|
+
}
|
|
90
|
+
getMousePos() {
|
|
91
|
+
return this.getLibnutOrThrow('getMousePos').getMousePos();
|
|
92
|
+
}
|
|
93
|
+
moveMouse(x, y) {
|
|
94
|
+
this.getLibnutOrThrow('moveMouse').moveMouse(x, y);
|
|
95
|
+
}
|
|
96
|
+
mouseClick(button, double) {
|
|
97
|
+
const lib = this.getLibnutOrThrow('mouseClick');
|
|
98
|
+
if (void 0 !== double) lib.mouseClick(button, double);
|
|
99
|
+
else if (void 0 !== button) lib.mouseClick(button);
|
|
100
|
+
else lib.mouseClick();
|
|
101
|
+
}
|
|
102
|
+
mouseToggle(state, button = 'left') {
|
|
103
|
+
this.getLibnutOrThrow('mouseToggle').mouseToggle(state, button);
|
|
104
|
+
}
|
|
105
|
+
scrollMouse(x, y) {
|
|
106
|
+
this.getLibnutOrThrow('scrollMouse').scrollMouse(x, y);
|
|
107
|
+
}
|
|
108
|
+
keyTap(key, modifiers) {
|
|
109
|
+
const lib = this.getLibnutOrThrow('keyTap');
|
|
110
|
+
if (void 0 !== modifiers) lib.keyTap(key, modifiers);
|
|
111
|
+
else lib.keyTap(key);
|
|
112
|
+
}
|
|
113
|
+
sendKeyViaAppleScript(key, modifiers = []) {
|
|
114
|
+
this.assertActive('sendKeyViaAppleScript');
|
|
115
|
+
this.options.sendKeyViaAppleScript(key, modifiers);
|
|
116
|
+
}
|
|
117
|
+
sendKey(key, modifiers = []) {
|
|
118
|
+
if (this.options.useAppleScript()) return void this.sendKeyViaAppleScript(key, modifiers);
|
|
119
|
+
if (modifiers.length > 0) this.keyTap(key, modifiers);
|
|
120
|
+
else this.keyTap(key);
|
|
121
|
+
}
|
|
122
|
+
runPhasedScroll(direction, pixels, steps) {
|
|
123
|
+
this.assertActive('runPhasedScroll');
|
|
124
|
+
return this.options.runPhasedScroll(direction, pixels, steps);
|
|
125
|
+
}
|
|
126
|
+
async delay(ms) {
|
|
127
|
+
this.assertActive('delay');
|
|
128
|
+
return new Promise((resolve, reject)=>{
|
|
129
|
+
const waitRef = {
|
|
130
|
+
timeoutId: setTimeout(()=>{
|
|
131
|
+
this.pendingInputDelayWaits.delete(waitRef);
|
|
132
|
+
try {
|
|
133
|
+
this.assertActive('delay');
|
|
134
|
+
resolve();
|
|
135
|
+
} catch (error) {
|
|
136
|
+
reject(error);
|
|
137
|
+
}
|
|
138
|
+
}, ms),
|
|
139
|
+
reject
|
|
140
|
+
};
|
|
141
|
+
this.pendingInputDelayWaits.add(waitRef);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
async smoothMoveMouse(targetX, targetY, steps, stepDelay) {
|
|
145
|
+
const currentPos = this.getMousePos();
|
|
146
|
+
for(let i = 1; i <= steps; i++){
|
|
147
|
+
const stepX = Math.round(currentPos.x + (targetX - currentPos.x) * i / steps);
|
|
148
|
+
const stepY = Math.round(currentPos.y + (targetY - currentPos.y) * i / steps);
|
|
149
|
+
this.moveMouse(stepX, stepY);
|
|
150
|
+
await this.delay(stepDelay);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
async withMouseButton(button, run) {
|
|
154
|
+
this.mouseToggle('down', button);
|
|
155
|
+
try {
|
|
156
|
+
return await run();
|
|
157
|
+
} finally{
|
|
158
|
+
this.releaseMouseButton(button);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
getLibnutOrThrow(methodName) {
|
|
162
|
+
this.assertActive(methodName);
|
|
163
|
+
const libnut = this.options.getLibnut();
|
|
164
|
+
external_node_assert_default()(libnut, 'libnut not initialized');
|
|
165
|
+
return libnut;
|
|
166
|
+
}
|
|
167
|
+
assertActive(methodName) {
|
|
168
|
+
if (this.destroyed) throw this.createDestroyedError(methodName);
|
|
169
|
+
}
|
|
170
|
+
createDestroyedError(methodName) {
|
|
171
|
+
return new Error(`ComputerDevice has been destroyed (cannot run ${methodName})`);
|
|
172
|
+
}
|
|
173
|
+
releaseMouseButton(button) {
|
|
174
|
+
try {
|
|
175
|
+
const libnut = this.options.getLibnut();
|
|
176
|
+
external_node_assert_default()(libnut, 'libnut not initialized');
|
|
177
|
+
libnut.mouseToggle('up', button);
|
|
178
|
+
} catch (error) {
|
|
179
|
+
this.options.debug(`Failed to release mouse button ${button}: ${error}`);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
rejectPendingInputDelays() {
|
|
183
|
+
const error = this.createDestroyedError('in-flight input');
|
|
184
|
+
for (const waitRef of this.pendingInputDelayWaits){
|
|
185
|
+
clearTimeout(waitRef.timeoutId);
|
|
186
|
+
waitRef.reject(error);
|
|
187
|
+
}
|
|
188
|
+
this.pendingInputDelayWaits.clear();
|
|
189
|
+
}
|
|
190
|
+
constructor(options){
|
|
191
|
+
_define_property(this, "options", void 0);
|
|
192
|
+
_define_property(this, "destroyed", void 0);
|
|
193
|
+
_define_property(this, "pendingInputDelayWaits", void 0);
|
|
194
|
+
this.options = options;
|
|
195
|
+
this.destroyed = false;
|
|
196
|
+
this.pendingInputDelayWaits = new Set();
|
|
197
|
+
}
|
|
198
|
+
}
|
|
71
199
|
const debugXvfb = (0, logger_namespaceObject.getDebug)('computer:xvfb');
|
|
72
200
|
function checkXvfbInstalled() {
|
|
73
201
|
try {
|
|
@@ -135,7 +263,7 @@ function needsXvfb(explicitOpt) {
|
|
|
135
263
|
if ('linux' !== process.platform) return false;
|
|
136
264
|
return true === explicitOpt;
|
|
137
265
|
}
|
|
138
|
-
function
|
|
266
|
+
function device_define_property(obj, key, value) {
|
|
139
267
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
140
268
|
value: value,
|
|
141
269
|
enumerable: true,
|
|
@@ -336,16 +464,6 @@ function runPhasedScroll(direction, pixels, steps) {
|
|
|
336
464
|
return false;
|
|
337
465
|
}
|
|
338
466
|
}
|
|
339
|
-
async function smoothMoveMouse(targetX, targetY, steps, stepDelay) {
|
|
340
|
-
external_node_assert_default()(device_libnut, 'libnut not initialized');
|
|
341
|
-
const currentPos = device_libnut.getMousePos();
|
|
342
|
-
for(let i = 1; i <= steps; i++){
|
|
343
|
-
const stepX = Math.round(currentPos.x + (targetX - currentPos.x) * i / steps);
|
|
344
|
-
const stepY = Math.round(currentPos.y + (targetY - currentPos.y) * i / steps);
|
|
345
|
-
device_libnut.moveMouse(stepX, stepY);
|
|
346
|
-
await (0, utils_namespaceObject.sleep)(stepDelay);
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
467
|
const KEY_NAME_MAP = {
|
|
350
468
|
windows: 'win',
|
|
351
469
|
win: 'win',
|
|
@@ -455,7 +573,7 @@ Available Displays: ${displays.length > 0 ? displays.map((d)=>d.name).join(', ')
|
|
|
455
573
|
}
|
|
456
574
|
async healthCheck() {
|
|
457
575
|
console.log('[HealthCheck] Starting health check...');
|
|
458
|
-
console.log("[HealthCheck] @midscene/computer v1.8.
|
|
576
|
+
console.log("[HealthCheck] @midscene/computer v1.8.7-beta-20260527113633.0");
|
|
459
577
|
console.log('[HealthCheck] Taking screenshot...');
|
|
460
578
|
const screenshotTimeout = 15000;
|
|
461
579
|
let timeoutId;
|
|
@@ -468,17 +586,16 @@ Available Displays: ${displays.length > 0 ? displays.map((d)=>d.name).join(', ')
|
|
|
468
586
|
]);
|
|
469
587
|
console.log(`[HealthCheck] Screenshot succeeded (length=${base64.length})`);
|
|
470
588
|
console.log('[HealthCheck] Moving mouse...');
|
|
471
|
-
|
|
472
|
-
const startPos = device_libnut.getMousePos();
|
|
589
|
+
const startPos = this.inputDriver.getMousePos();
|
|
473
590
|
console.log(`[HealthCheck] Current mouse position: (${startPos.x}, ${startPos.y})`);
|
|
474
591
|
const offsetX = Math.floor(40 * Math.random()) + 10;
|
|
475
592
|
const offsetY = Math.floor(40 * Math.random()) + 10;
|
|
476
593
|
const targetX = startPos.x + offsetX;
|
|
477
594
|
const targetY = startPos.y + offsetY;
|
|
478
595
|
console.log(`[HealthCheck] Moving mouse to (${targetX}, ${targetY})...`);
|
|
479
|
-
|
|
596
|
+
this.inputDriver.moveMouse(targetX, targetY);
|
|
480
597
|
await (0, utils_namespaceObject.sleep)(50);
|
|
481
|
-
const movedPos =
|
|
598
|
+
const movedPos = this.inputDriver.getMousePos();
|
|
482
599
|
console.log(`[HealthCheck] Mouse position after move: (${movedPos.x}, ${movedPos.y})`);
|
|
483
600
|
const deltaX = Math.abs(movedPos.x - targetX);
|
|
484
601
|
const deltaY = Math.abs(movedPos.y - targetY);
|
|
@@ -492,7 +609,7 @@ Available Displays: ${displays.length > 0 ? displays.map((d)=>d.name).join(', ')
|
|
|
492
609
|
debugDevice(hint);
|
|
493
610
|
}
|
|
494
611
|
}
|
|
495
|
-
|
|
612
|
+
this.inputDriver.moveMouse(startPos.x, startPos.y);
|
|
496
613
|
console.log(`[HealthCheck] Mouse restored to (${startPos.x}, ${startPos.y})`);
|
|
497
614
|
console.log('[HealthCheck] Listing monitors...');
|
|
498
615
|
const displays = await ComputerDevice.listDisplays();
|
|
@@ -555,9 +672,8 @@ Original error: ${lastRawMessage}`);
|
|
|
555
672
|
throw new Error(`Failed to take screenshot: ${lastRawMessage}`);
|
|
556
673
|
}
|
|
557
674
|
async size() {
|
|
558
|
-
external_node_assert_default()(device_libnut, 'libnut not initialized');
|
|
559
675
|
try {
|
|
560
|
-
const screenSize =
|
|
676
|
+
const screenSize = this.inputDriver.getScreenSize();
|
|
561
677
|
return {
|
|
562
678
|
width: screenSize.width,
|
|
563
679
|
height: screenSize.height
|
|
@@ -568,7 +684,6 @@ Original error: ${lastRawMessage}`);
|
|
|
568
684
|
}
|
|
569
685
|
}
|
|
570
686
|
async typeViaClipboard(text) {
|
|
571
|
-
external_node_assert_default()(device_libnut, 'libnut not initialized');
|
|
572
687
|
debugDevice('Using clipboard to input text', {
|
|
573
688
|
textLength: text.length,
|
|
574
689
|
preview: text.substring(0, 20)
|
|
@@ -577,17 +692,17 @@ Original error: ${lastRawMessage}`);
|
|
|
577
692
|
const oldClipboard = await clipboardy.default.read().catch(()=>'');
|
|
578
693
|
try {
|
|
579
694
|
await clipboardy.default.write(text);
|
|
580
|
-
await
|
|
581
|
-
if (this.useAppleScript) sendKeyViaAppleScript('v', [
|
|
695
|
+
await this.inputDriver.delay(50);
|
|
696
|
+
if (this.useAppleScript) this.inputDriver.sendKeyViaAppleScript('v', [
|
|
582
697
|
'command'
|
|
583
698
|
]);
|
|
584
699
|
else {
|
|
585
700
|
const modifier = 'darwin' === process.platform ? 'command' : 'control';
|
|
586
|
-
|
|
701
|
+
this.inputDriver.keyTap('v', [
|
|
587
702
|
modifier
|
|
588
703
|
]);
|
|
589
704
|
}
|
|
590
|
-
await
|
|
705
|
+
await this.inputDriver.delay(100);
|
|
591
706
|
} finally{
|
|
592
707
|
if (oldClipboard) await clipboardy.default.write(oldClipboard).catch(()=>{
|
|
593
708
|
debugDevice('Failed to restore clipboard content');
|
|
@@ -595,28 +710,25 @@ Original error: ${lastRawMessage}`);
|
|
|
595
710
|
}
|
|
596
711
|
}
|
|
597
712
|
async smartTypeString(text) {
|
|
598
|
-
external_node_assert_default()(device_libnut, 'libnut not initialized');
|
|
599
713
|
await this.typeViaClipboard(text);
|
|
600
714
|
}
|
|
601
715
|
async selectAllAndDelete() {
|
|
602
|
-
external_node_assert_default()(device_libnut, 'libnut not initialized');
|
|
603
716
|
if (this.useAppleScript) {
|
|
604
|
-
sendKeyViaAppleScript('a', [
|
|
717
|
+
this.inputDriver.sendKeyViaAppleScript('a', [
|
|
605
718
|
'command'
|
|
606
719
|
]);
|
|
607
|
-
await
|
|
608
|
-
sendKeyViaAppleScript('backspace', []);
|
|
720
|
+
await this.inputDriver.delay(50);
|
|
721
|
+
this.inputDriver.sendKeyViaAppleScript('backspace', []);
|
|
609
722
|
return;
|
|
610
723
|
}
|
|
611
724
|
const modifier = 'darwin' === process.platform ? 'command' : 'control';
|
|
612
|
-
|
|
725
|
+
this.inputDriver.keyTap('a', [
|
|
613
726
|
modifier
|
|
614
727
|
]);
|
|
615
|
-
await
|
|
616
|
-
|
|
728
|
+
await this.inputDriver.delay(50);
|
|
729
|
+
this.inputDriver.keyTap('backspace');
|
|
617
730
|
}
|
|
618
731
|
async pressKeyboardShortcut(keyName) {
|
|
619
|
-
external_node_assert_default()(device_libnut, 'libnut not initialized');
|
|
620
732
|
const keys = keyName.split('+');
|
|
621
733
|
const modifiers = keys.slice(0, -1).map(normalizeKeyName);
|
|
622
734
|
const key = normalizePrimaryKey(keys[keys.length - 1]);
|
|
@@ -626,30 +738,27 @@ Original error: ${lastRawMessage}`);
|
|
|
626
738
|
modifiers,
|
|
627
739
|
driver: this.useAppleScript ? "applescript" : 'libnut'
|
|
628
740
|
});
|
|
629
|
-
|
|
630
|
-
else if (modifiers.length > 0) device_libnut.keyTap(key, modifiers);
|
|
631
|
-
else device_libnut.keyTap(key);
|
|
741
|
+
this.inputDriver.sendKey(key, modifiers);
|
|
632
742
|
}
|
|
633
743
|
async performScroll(param) {
|
|
634
|
-
external_node_assert_default()(device_libnut, 'libnut not initialized');
|
|
635
744
|
if (param.locate) {
|
|
636
745
|
const element = param.locate;
|
|
637
746
|
const [x, y] = element.center;
|
|
638
|
-
|
|
747
|
+
this.inputDriver.moveMouse(Math.round(x), Math.round(y));
|
|
639
748
|
}
|
|
640
749
|
const scrollType = param?.scrollType;
|
|
641
750
|
const edgeSpec = scrollType && scrollType in EDGE_SCROLL_SPEC ? EDGE_SCROLL_SPEC[scrollType] : null;
|
|
642
751
|
if (edgeSpec) {
|
|
643
|
-
if (runPhasedScroll(edgeSpec.direction, EDGE_SCROLL_TOTAL_PX, EDGE_SCROLL_STEPS)) return void await
|
|
752
|
+
if (this.inputDriver.runPhasedScroll(edgeSpec.direction, EDGE_SCROLL_TOTAL_PX, EDGE_SCROLL_STEPS)) return void await this.inputDriver.delay(SCROLL_COMPLETE_DELAY);
|
|
644
753
|
if (this.useAppleScript) {
|
|
645
|
-
sendKeyViaAppleScript(edgeSpec.key);
|
|
646
|
-
await
|
|
754
|
+
this.inputDriver.sendKeyViaAppleScript(edgeSpec.key);
|
|
755
|
+
await this.inputDriver.delay(SCROLL_COMPLETE_DELAY);
|
|
647
756
|
return;
|
|
648
757
|
}
|
|
649
758
|
const [dx, dy] = edgeSpec.libnut;
|
|
650
759
|
for(let i = 0; i < SCROLL_REPEAT_COUNT; i++){
|
|
651
|
-
|
|
652
|
-
await
|
|
760
|
+
this.inputDriver.scrollMouse(dx, dy);
|
|
761
|
+
await this.inputDriver.delay(SCROLL_STEP_DELAY);
|
|
653
762
|
}
|
|
654
763
|
return;
|
|
655
764
|
}
|
|
@@ -666,17 +775,17 @@ Original error: ${lastRawMessage}`);
|
|
|
666
775
|
}
|
|
667
776
|
if (isKnownDirection) {
|
|
668
777
|
const steps = Math.max(PHASED_MIN_STEPS, Math.round(distance / PHASED_PIXELS_PER_STEP));
|
|
669
|
-
if (runPhasedScroll(direction, distance, steps)) return void await
|
|
778
|
+
if (this.inputDriver.runPhasedScroll(direction, distance, steps)) return void await this.inputDriver.delay(SCROLL_COMPLETE_DELAY);
|
|
670
779
|
}
|
|
671
780
|
if (this.useAppleScript && ('up' === direction || 'down' === direction)) {
|
|
672
781
|
if (!screenSize) screenSize = await this.size();
|
|
673
782
|
const pages = Math.max(1, Math.round(distance / screenSize.height));
|
|
674
783
|
const key = 'up' === direction ? 'pageup' : 'pagedown';
|
|
675
784
|
for(let i = 0; i < pages; i++){
|
|
676
|
-
sendKeyViaAppleScript(key);
|
|
677
|
-
await
|
|
785
|
+
this.inputDriver.sendKeyViaAppleScript(key);
|
|
786
|
+
await this.inputDriver.delay(SCROLL_STEP_DELAY);
|
|
678
787
|
}
|
|
679
|
-
await
|
|
788
|
+
await this.inputDriver.delay(SCROLL_COMPLETE_DELAY);
|
|
680
789
|
return;
|
|
681
790
|
}
|
|
682
791
|
const ticks = Math.ceil(distance / 100);
|
|
@@ -702,8 +811,8 @@ Original error: ${lastRawMessage}`);
|
|
|
702
811
|
0,
|
|
703
812
|
-ticks
|
|
704
813
|
];
|
|
705
|
-
|
|
706
|
-
await
|
|
814
|
+
this.inputDriver.scrollMouse(dx, dy);
|
|
815
|
+
await this.inputDriver.delay(SCROLL_COMPLETE_DELAY);
|
|
707
816
|
return;
|
|
708
817
|
}
|
|
709
818
|
throw new Error(`Unknown scroll type: ${scrollType}, param: ${JSON.stringify(param)}`);
|
|
@@ -722,6 +831,8 @@ Original error: ${lastRawMessage}`);
|
|
|
722
831
|
}
|
|
723
832
|
async destroy() {
|
|
724
833
|
if (this.destroyed) return;
|
|
834
|
+
this.destroyed = true;
|
|
835
|
+
this.inputDriver.destroy();
|
|
725
836
|
if (this.xvfbInstance) {
|
|
726
837
|
this.xvfbInstance.stop();
|
|
727
838
|
this.xvfbInstance = void 0;
|
|
@@ -732,96 +843,94 @@ Original error: ${lastRawMessage}`);
|
|
|
732
843
|
process.removeListener('SIGTERM', this.xvfbCleanup);
|
|
733
844
|
this.xvfbCleanup = void 0;
|
|
734
845
|
}
|
|
735
|
-
this.destroyed = true;
|
|
736
846
|
debugDevice('Computer device destroyed');
|
|
737
847
|
}
|
|
738
848
|
async url() {
|
|
739
849
|
return '';
|
|
740
850
|
}
|
|
741
851
|
constructor(options){
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
852
|
+
device_define_property(this, "interfaceType", 'computer');
|
|
853
|
+
device_define_property(this, "options", void 0);
|
|
854
|
+
device_define_property(this, "displayId", void 0);
|
|
855
|
+
device_define_property(this, "description", void 0);
|
|
856
|
+
device_define_property(this, "destroyed", false);
|
|
857
|
+
device_define_property(this, "xvfbInstance", void 0);
|
|
858
|
+
device_define_property(this, "xvfbCleanup", void 0);
|
|
859
|
+
device_define_property(this, "inputDriver", new ComputerInputDriver({
|
|
860
|
+
getLibnut: ()=>device_libnut,
|
|
861
|
+
useAppleScript: ()=>this.useAppleScript,
|
|
862
|
+
sendKeyViaAppleScript,
|
|
863
|
+
runPhasedScroll,
|
|
864
|
+
debug: (message)=>debugDevice(message)
|
|
865
|
+
}));
|
|
866
|
+
device_define_property(this, "useAppleScript", void 0);
|
|
867
|
+
device_define_property(this, "uri", void 0);
|
|
868
|
+
device_define_property(this, "inputPrimitives", {
|
|
752
869
|
pointer: {
|
|
753
870
|
tap: async ({ x, y })=>{
|
|
754
|
-
external_node_assert_default()(device_libnut, 'libnut not initialized');
|
|
755
871
|
const targetX = Math.round(x);
|
|
756
872
|
const targetY = Math.round(y);
|
|
757
|
-
await smoothMoveMouse(targetX, targetY, SMOOTH_MOVE_STEPS_TAP, SMOOTH_MOVE_DELAY_TAP);
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
873
|
+
await this.inputDriver.smoothMoveMouse(targetX, targetY, SMOOTH_MOVE_STEPS_TAP, SMOOTH_MOVE_DELAY_TAP);
|
|
874
|
+
await this.inputDriver.withMouseButton('left', async ()=>{
|
|
875
|
+
await this.inputDriver.delay(CLICK_HOLD_DURATION);
|
|
876
|
+
});
|
|
761
877
|
},
|
|
762
878
|
doubleClick: async ({ x, y })=>{
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
device_libnut.mouseClick('left', true);
|
|
879
|
+
this.inputDriver.moveMouse(Math.round(x), Math.round(y));
|
|
880
|
+
this.inputDriver.mouseClick('left', true);
|
|
766
881
|
},
|
|
767
882
|
rightClick: async ({ x, y })=>{
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
device_libnut.mouseClick('right');
|
|
883
|
+
this.inputDriver.moveMouse(Math.round(x), Math.round(y));
|
|
884
|
+
this.inputDriver.mouseClick('right');
|
|
771
885
|
},
|
|
772
886
|
hover: async ({ x, y })=>{
|
|
773
|
-
|
|
774
|
-
await
|
|
775
|
-
await (0, utils_namespaceObject.sleep)(MOUSE_MOVE_EFFECT_WAIT);
|
|
887
|
+
await this.inputDriver.smoothMoveMouse(Math.round(x), Math.round(y), SMOOTH_MOVE_STEPS_MOUSE_MOVE, SMOOTH_MOVE_DELAY_MOUSE_MOVE);
|
|
888
|
+
await this.inputDriver.delay(MOUSE_MOVE_EFFECT_WAIT);
|
|
776
889
|
},
|
|
777
890
|
dragAndDrop: async (from, to)=>{
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
device_libnut.mouseToggle('up', 'left');
|
|
891
|
+
this.inputDriver.moveMouse(Math.round(from.x), Math.round(from.y));
|
|
892
|
+
await this.inputDriver.withMouseButton('left', async ()=>{
|
|
893
|
+
await this.inputDriver.delay(100);
|
|
894
|
+
this.inputDriver.moveMouse(Math.round(to.x), Math.round(to.y));
|
|
895
|
+
await this.inputDriver.delay(100);
|
|
896
|
+
});
|
|
785
897
|
}
|
|
786
898
|
},
|
|
787
899
|
keyboard: {
|
|
788
900
|
typeText: async (value, opts)=>{
|
|
789
|
-
external_node_assert_default()(device_libnut, 'libnut not initialized');
|
|
790
901
|
const element = opts?.target;
|
|
791
902
|
if (element) {
|
|
792
903
|
const [x, y] = element.center;
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
await
|
|
904
|
+
this.inputDriver.moveMouse(Math.round(x), Math.round(y));
|
|
905
|
+
this.inputDriver.mouseClick('left');
|
|
906
|
+
await this.inputDriver.delay(INPUT_FOCUS_DELAY);
|
|
796
907
|
if (opts?.replace !== false) {
|
|
797
908
|
await this.selectAllAndDelete();
|
|
798
|
-
await
|
|
909
|
+
await this.inputDriver.delay(INPUT_CLEAR_DELAY);
|
|
799
910
|
}
|
|
800
911
|
}
|
|
801
912
|
await this.smartTypeString(value);
|
|
802
913
|
},
|
|
803
914
|
keyboardPress: async (keyName, opts)=>{
|
|
804
|
-
external_node_assert_default()(device_libnut, 'libnut not initialized');
|
|
805
915
|
const target = opts?.target;
|
|
806
916
|
if (target) {
|
|
807
917
|
const [x, y] = target.center;
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
await
|
|
918
|
+
this.inputDriver.moveMouse(Math.round(x), Math.round(y));
|
|
919
|
+
this.inputDriver.mouseClick('left');
|
|
920
|
+
await this.inputDriver.delay(50);
|
|
811
921
|
}
|
|
812
922
|
await this.pressKeyboardShortcut(keyName);
|
|
813
923
|
},
|
|
814
924
|
clearInput: async (target)=>{
|
|
815
|
-
external_node_assert_default()(device_libnut, 'libnut not initialized');
|
|
816
925
|
if (target) {
|
|
817
926
|
const element = target;
|
|
818
927
|
const [x, y] = element.center;
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
await
|
|
928
|
+
this.inputDriver.moveMouse(Math.round(x), Math.round(y));
|
|
929
|
+
this.inputDriver.mouseClick('left');
|
|
930
|
+
await this.inputDriver.delay(100);
|
|
822
931
|
}
|
|
823
932
|
await this.selectAllAndDelete();
|
|
824
|
-
await
|
|
933
|
+
await this.inputDriver.delay(50);
|
|
825
934
|
}
|
|
826
935
|
},
|
|
827
936
|
scroll: {
|
|
@@ -1186,7 +1295,7 @@ class HelperProcessRDPBackendClient {
|
|
|
1186
1295
|
function createDefaultRDPBackendClient() {
|
|
1187
1296
|
return new HelperProcessRDPBackendClient();
|
|
1188
1297
|
}
|
|
1189
|
-
function
|
|
1298
|
+
function rdp_device_define_property(obj, key, value) {
|
|
1190
1299
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
1191
1300
|
value: value,
|
|
1192
1301
|
enumerable: true,
|
|
@@ -1345,14 +1454,14 @@ class RDPDevice {
|
|
|
1345
1454
|
}
|
|
1346
1455
|
}
|
|
1347
1456
|
constructor(options){
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1457
|
+
rdp_device_define_property(this, "interfaceType", 'rdp');
|
|
1458
|
+
rdp_device_define_property(this, "options", void 0);
|
|
1459
|
+
rdp_device_define_property(this, "backend", void 0);
|
|
1460
|
+
rdp_device_define_property(this, "connectionInfo", void 0);
|
|
1461
|
+
rdp_device_define_property(this, "destroyed", false);
|
|
1462
|
+
rdp_device_define_property(this, "cursorPosition", void 0);
|
|
1463
|
+
rdp_device_define_property(this, "uri", void 0);
|
|
1464
|
+
rdp_device_define_property(this, "inputPrimitives", {
|
|
1356
1465
|
pointer: {
|
|
1357
1466
|
tap: async ({ x, y })=>{
|
|
1358
1467
|
await this.movePointer(Math.round(x), Math.round(y), {
|
|
@@ -1687,7 +1796,7 @@ class ComputerMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
|
|
|
1687
1796
|
}
|
|
1688
1797
|
const env_namespaceObject = require("@midscene/shared/env");
|
|
1689
1798
|
function version() {
|
|
1690
|
-
const currentVersion = "1.8.
|
|
1799
|
+
const currentVersion = "1.8.7-beta-20260527113633.0";
|
|
1691
1800
|
console.log(`@midscene/computer v${currentVersion}`);
|
|
1692
1801
|
return currentVersion;
|
|
1693
1802
|
}
|