@midscene/computer 1.12.4-beta-20260904041024.0 → 1.12.4

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/lib/cli.js CHANGED
@@ -42,210 +42,6 @@ const utils_namespaceObject = require("@midscene/core/utils");
42
42
  const img_namespaceObject = require("@midscene/shared/img");
43
43
  const external_screenshot_desktop_namespaceObject = require("screenshot-desktop");
44
44
  var external_screenshot_desktop_default = /*#__PURE__*/ __webpack_require__.n(external_screenshot_desktop_namespaceObject);
45
- const US_SHIFTED_CHARACTER_KEYS = new Map([
46
- [
47
- '~',
48
- '`'
49
- ],
50
- [
51
- '!',
52
- '1'
53
- ],
54
- [
55
- '@',
56
- '2'
57
- ],
58
- [
59
- '#',
60
- '3'
61
- ],
62
- [
63
- '$',
64
- '4'
65
- ],
66
- [
67
- '%',
68
- '5'
69
- ],
70
- [
71
- '^',
72
- '6'
73
- ],
74
- [
75
- '&',
76
- '7'
77
- ],
78
- [
79
- '*',
80
- '8'
81
- ],
82
- [
83
- '(',
84
- '9'
85
- ],
86
- [
87
- ')',
88
- '0'
89
- ],
90
- [
91
- '_',
92
- '-'
93
- ],
94
- [
95
- '+',
96
- '='
97
- ],
98
- [
99
- '{',
100
- '['
101
- ],
102
- [
103
- '}',
104
- ']'
105
- ],
106
- [
107
- '|',
108
- '\\'
109
- ],
110
- [
111
- ':',
112
- ';'
113
- ],
114
- [
115
- '"',
116
- "'"
117
- ],
118
- [
119
- '<',
120
- ','
121
- ],
122
- [
123
- '>',
124
- '.'
125
- ],
126
- [
127
- '?',
128
- '/'
129
- ]
130
- ]);
131
- const debugKeyboard = (0, logger_namespaceObject.getDebug)('computer:keyboard');
132
- const APPLE_SCRIPT_KEY_CODES = {
133
- return: 36,
134
- enter: 36,
135
- tab: 48,
136
- space: 49,
137
- backspace: 51,
138
- delete: 51,
139
- escape: 53,
140
- forwarddelete: 117,
141
- left: 123,
142
- right: 124,
143
- down: 125,
144
- up: 126,
145
- home: 115,
146
- end: 119,
147
- pageup: 116,
148
- pagedown: 121,
149
- f1: 122,
150
- f2: 120,
151
- f3: 99,
152
- f4: 118,
153
- f5: 96,
154
- f6: 97,
155
- f7: 98,
156
- f8: 100,
157
- f9: 101,
158
- f10: 109,
159
- f11: 103,
160
- f12: 111
161
- };
162
- const APPLE_SCRIPT_MODIFIER_KEYS = {
163
- command: 'command',
164
- cmd: 'command',
165
- control: 'control',
166
- ctrl: 'control',
167
- shift: 'shift',
168
- alt: 'option',
169
- option: 'option',
170
- meta: 'command'
171
- };
172
- function buildKeyCommand(key) {
173
- const keyCode = APPLE_SCRIPT_KEY_CODES[key.toLowerCase()];
174
- if (void 0 !== keyCode) return `key code ${keyCode}`;
175
- const escapedKey = key.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
176
- return `keystroke "${escapedKey}"`;
177
- }
178
- function resolveModifierKeys(modifiers) {
179
- return modifiers.map((modifier)=>APPLE_SCRIPT_MODIFIER_KEYS[modifier.toLowerCase()]).filter((modifier)=>void 0 !== modifier);
180
- }
181
- function buildLogicalKeyPress(key, modifiers) {
182
- const modifierKeys = resolveModifierKeys(modifiers);
183
- const modifierClause = modifierKeys.length ? ` using {${modifierKeys.map((modifier)=>`${modifier} down`).join(', ')}}` : '';
184
- return `tell application "System Events" to ${buildKeyCommand(key)}${modifierClause}`;
185
- }
186
- function resolvePhysicalKey(key, modifiers) {
187
- const resolvedModifiers = [
188
- ...modifiers
189
- ];
190
- const shiftedBaseKey = US_SHIFTED_CHARACTER_KEYS.get(key);
191
- if (/^[A-Z]$/.test(key)) {
192
- resolvedModifiers.push('shift');
193
- return {
194
- key: key.toLowerCase(),
195
- modifiers: resolvedModifiers
196
- };
197
- }
198
- if (void 0 !== shiftedBaseKey) {
199
- resolvedModifiers.push('shift');
200
- return {
201
- key: shiftedBaseKey,
202
- modifiers: resolvedModifiers
203
- };
204
- }
205
- return {
206
- key,
207
- modifiers: resolvedModifiers
208
- };
209
- }
210
- function buildPhysicalKeyPress(key, modifiers) {
211
- const resolved = resolvePhysicalKey(key, modifiers);
212
- const modifierKeys = [
213
- ...new Set(resolveModifierKeys(resolved.modifiers))
214
- ];
215
- const keyCommand = buildKeyCommand(resolved.key);
216
- if (0 === modifierKeys.length) return `tell application "System Events" to ${keyCommand}`;
217
- const releaseCommands = [
218
- ...modifierKeys
219
- ].reverse().map((modifier)=>`key up ${modifier}`);
220
- return [
221
- 'tell application "System Events"',
222
- 'try',
223
- ...modifierKeys.map((modifier)=>`key down ${modifier}`),
224
- keyCommand,
225
- 'on error errorMessage number errorNumber',
226
- ...releaseCommands,
227
- 'error errorMessage number errorNumber',
228
- 'end try',
229
- ...releaseCommands,
230
- 'end tell'
231
- ].join('\n');
232
- }
233
- function buildAppleScriptKeyPress(key, modifiers = [], eventMode = 'logical') {
234
- return 'physical' === eventMode ? buildPhysicalKeyPress(key, modifiers) : buildLogicalKeyPress(key, modifiers);
235
- }
236
- function sendKeyViaAppleScript(key, modifiers = [], eventMode = 'logical') {
237
- const script = buildAppleScriptKeyPress(key, modifiers, eventMode);
238
- debugKeyboard('sendKeyViaAppleScript', {
239
- key,
240
- modifiers,
241
- eventMode,
242
- script
243
- });
244
- (0, external_node_child_process_namespaceObject.execFileSync)("osascript", [
245
- '-e',
246
- script
247
- ]);
248
- }
249
45
  const external_node_assert_namespaceObject = require("node:assert");
250
46
  var external_node_assert_default = /*#__PURE__*/ __webpack_require__.n(external_node_assert_namespaceObject);
251
47
  function _define_property(obj, key, value) {
@@ -771,6 +567,92 @@ const LIBNUT_FALLBACK_PIXELS_PER_DETENT = 100;
771
567
  const LIBNUT_FALLBACK_TICK_DELAY_MS = 30;
772
568
  const LIBNUT_FALLBACK_MAX_DETENTS = 200;
773
569
  const LIBNUT_FALLBACK_DETENT_AMOUNT = 'win32' === process.platform ? 120 : 1;
570
+ const LINUX_SHIFTED_CHARACTER_KEYS = new Map([
571
+ [
572
+ '~',
573
+ '`'
574
+ ],
575
+ [
576
+ '!',
577
+ '1'
578
+ ],
579
+ [
580
+ '@',
581
+ '2'
582
+ ],
583
+ [
584
+ '#',
585
+ '3'
586
+ ],
587
+ [
588
+ '$',
589
+ '4'
590
+ ],
591
+ [
592
+ '%',
593
+ '5'
594
+ ],
595
+ [
596
+ '^',
597
+ '6'
598
+ ],
599
+ [
600
+ '&',
601
+ '7'
602
+ ],
603
+ [
604
+ '*',
605
+ '8'
606
+ ],
607
+ [
608
+ '(',
609
+ '9'
610
+ ],
611
+ [
612
+ ')',
613
+ '0'
614
+ ],
615
+ [
616
+ '_',
617
+ '-'
618
+ ],
619
+ [
620
+ '+',
621
+ '='
622
+ ],
623
+ [
624
+ '{',
625
+ '['
626
+ ],
627
+ [
628
+ '}',
629
+ ']'
630
+ ],
631
+ [
632
+ '|',
633
+ '\\'
634
+ ],
635
+ [
636
+ ':',
637
+ ';'
638
+ ],
639
+ [
640
+ '"',
641
+ "'"
642
+ ],
643
+ [
644
+ '<',
645
+ ','
646
+ ],
647
+ [
648
+ '>',
649
+ '.'
650
+ ],
651
+ [
652
+ '?',
653
+ '/'
654
+ ]
655
+ ]);
774
656
  const LIBNUT_FALLBACK_EDGE_DETENTS = Math.min(LIBNUT_FALLBACK_MAX_DETENTS, Math.max(1, Math.ceil(EDGE_SCROLL_TOTAL_PX / LIBNUT_FALLBACK_PIXELS_PER_DETENT)));
775
657
  const DEFAULT_SCROLL_VIEWPORT_RATIO = 0.7;
776
658
  const EDGE_SCROLL_SPEC = {
@@ -807,6 +689,67 @@ const EDGE_SCROLL_SPEC = {
807
689
  ]
808
690
  }
809
691
  };
692
+ const APPLESCRIPT_KEY_CODE_MAP = {
693
+ return: 36,
694
+ enter: 36,
695
+ tab: 48,
696
+ space: 49,
697
+ backspace: 51,
698
+ delete: 51,
699
+ escape: 53,
700
+ forwarddelete: 117,
701
+ left: 123,
702
+ right: 124,
703
+ down: 125,
704
+ up: 126,
705
+ home: 115,
706
+ end: 119,
707
+ pageup: 116,
708
+ pagedown: 121,
709
+ f1: 122,
710
+ f2: 120,
711
+ f3: 99,
712
+ f4: 118,
713
+ f5: 96,
714
+ f6: 97,
715
+ f7: 98,
716
+ f8: 100,
717
+ f9: 101,
718
+ f10: 109,
719
+ f11: 103,
720
+ f12: 111
721
+ };
722
+ const APPLESCRIPT_MODIFIER_MAP = {
723
+ command: 'command down',
724
+ cmd: 'command down',
725
+ control: 'control down',
726
+ ctrl: 'control down',
727
+ shift: 'shift down',
728
+ alt: 'option down',
729
+ option: 'option down',
730
+ meta: 'command down'
731
+ };
732
+ function sendKeyViaAppleScript(key, modifiers = []) {
733
+ const lowerKey = key.toLowerCase();
734
+ const keyCode = APPLESCRIPT_KEY_CODE_MAP[lowerKey];
735
+ const modifierParts = modifiers.map((m)=>APPLESCRIPT_MODIFIER_MAP[m.toLowerCase()]).filter(Boolean);
736
+ const modifierStr = modifierParts.length > 0 ? ` using {${modifierParts.join(', ')}}` : '';
737
+ let script;
738
+ if (void 0 !== keyCode) script = `tell application "System Events" to key code ${keyCode}${modifierStr}`;
739
+ else {
740
+ const escapedKey = key.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
741
+ script = `tell application "System Events" to keystroke "${escapedKey}"${modifierStr}`;
742
+ }
743
+ debugDevice('sendKeyViaAppleScript', {
744
+ key,
745
+ modifiers,
746
+ script
747
+ });
748
+ (0, external_node_child_process_namespaceObject.execFileSync)("osascript", [
749
+ '-e',
750
+ script
751
+ ]);
752
+ }
810
753
  function escapePowershellSingleQuoted(value) {
811
754
  return value.replace(/'/g, "''");
812
755
  }
@@ -1234,7 +1177,7 @@ Available Displays: ${displays.length > 0 ? displays.map((d)=>d.name).join(', ')
1234
1177
  }
1235
1178
  async healthCheck(displays) {
1236
1179
  console.log('[HealthCheck] Starting health check...');
1237
- console.log("[HealthCheck] @midscene/computer v1.12.4-beta-20260904041024.0");
1180
+ console.log("[HealthCheck] @midscene/computer v1.12.4");
1238
1181
  console.log('[HealthCheck] Taking screenshot...');
1239
1182
  const screenshotTimeout = 15000;
1240
1183
  let timeoutId;
@@ -1429,7 +1372,7 @@ $g.Dispose(); $bmp.Dispose(); $ms.Dispose()
1429
1372
  async typeStringWithDelay(text, keyboardTypeDelay) {
1430
1373
  await (0, device_namespaceObject.sendTextSequentially)(text.replace(/\r\n?/g, '\n'), {
1431
1374
  sendCharacter: (character)=>{
1432
- const linuxShiftedKey = 'linux' === process.platform ? US_SHIFTED_CHARACTER_KEYS.get(character) : void 0;
1375
+ const linuxShiftedKey = 'linux' === process.platform ? LINUX_SHIFTED_CHARACTER_KEYS.get(character) : void 0;
1433
1376
  if ('\n' === character) this.inputDriver.sendKey('return');
1434
1377
  else if ('\t' === character) this.inputDriver.sendKey('tab');
1435
1378
  else if (' ' === character) this.inputDriver.sendKey('space');
@@ -1623,7 +1566,7 @@ $g.Dispose(); $bmp.Dispose(); $ms.Dispose()
1623
1566
  device_define_property(this, "inputDriver", new ComputerInputDriver({
1624
1567
  getLibnut: ()=>device_libnut,
1625
1568
  useAppleScript: ()=>this.useAppleScript,
1626
- sendKeyViaAppleScript: (key, modifiers)=>sendKeyViaAppleScript(key, modifiers, this.options?.keyboardEventMode ?? 'logical'),
1569
+ sendKeyViaAppleScript,
1627
1570
  runPhasedScroll,
1628
1571
  debug: (message)=>debugDevice(message)
1629
1572
  }));
@@ -2449,7 +2392,6 @@ function createLocalComputerDevice(opts) {
2449
2392
  keyboardTypeDelay: opts?.keyboardTypeDelay,
2450
2393
  inputStrategy: opts?.inputStrategy,
2451
2394
  keyboardDriver: opts?.keyboardDriver,
2452
- keyboardEventMode: opts?.keyboardEventMode,
2453
2395
  headless: opts?.headless,
2454
2396
  xvfbResolution: opts?.xvfbResolution,
2455
2397
  keepXvfbAliveUntilProcessExit: opts?.keepXvfbAliveUntilProcessExit
@@ -2507,10 +2449,6 @@ const computerInitArgShape = {
2507
2449
  headless: core_namespaceObject.z.boolean().optional().describe('Start virtual display via Xvfb (Linux local mode only). Ignored when host is set.'),
2508
2450
  keyboardTypeDelay: core_namespaceObject.z.number().finite().nonnegative().optional().describe('Finite non-negative delay in milliseconds between keystrokes. In "legacy" mode, positive values enable key-by-key input; zero or omitted uses clipboard input.'),
2509
2451
  inputStrategy: core_namespaceObject.z["enum"](device_namespaceObject.inputStrategies).optional().describe('Text input strategy. "legacy" (default) preserves current Computer behavior, "sequential" sends one Unicode code point at a time, and "bulk" uses one backend input operation. "bulk" requires keyboardTypeDelay to be omitted or set to 0.'),
2510
- keyboardEventMode: core_namespaceObject.z["enum"]([
2511
- 'logical',
2512
- 'physical'
2513
- ]).optional().describe('macOS AppleScript keyboard event mode for local control. "logical" (default) targets native apps; "physical" is only for VNC clients, assumes an en-US layout for shifted punctuation, and requires sequential text input or a positive keyboardTypeDelay. Ignored in RDP mode and outside the macOS AppleScript driver.'),
2514
2452
  host: core_namespaceObject.z.string().optional().describe('RDP host (FQDN or IP). Set this to switch into RDP mode.'),
2515
2453
  port: core_namespaceObject.z.number().optional().describe('RDP port (default 3389). Requires host.'),
2516
2454
  username: core_namespaceObject.z.string().optional().describe('RDP username. Requires host.'),
@@ -2527,7 +2465,7 @@ const computerInitArgShape = {
2527
2465
  function adaptComputerInitArgs(extracted) {
2528
2466
  if (!extracted || 0 === Object.keys(extracted).length) return;
2529
2467
  if (extracted.host) {
2530
- const { displayId: _d, headless: _h, keyboardEventMode: _k, ...rdpFields } = extracted;
2468
+ const { displayId: _d, headless: _h, ...rdpFields } = extracted;
2531
2469
  const host = normalizeRdpHost(extracted.host);
2532
2470
  return {
2533
2471
  mode: 'rdp',
@@ -2541,7 +2479,6 @@ function adaptComputerInitArgs(extracted) {
2541
2479
  headless: extracted.headless,
2542
2480
  keyboardTypeDelay: extracted.keyboardTypeDelay,
2543
2481
  inputStrategy: extracted.inputStrategy,
2544
- keyboardEventMode: extracted.keyboardEventMode,
2545
2482
  ...(0, agent_behavior_init_args_namespaceObject.extractAgentBehaviorInitArgs)(extracted) ?? {}
2546
2483
  };
2547
2484
  }
@@ -2593,7 +2530,6 @@ class ComputerMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
2593
2530
  const headless = opts?.mode === 'local' ? opts.headless : void 0;
2594
2531
  const keyboardTypeDelay = opts?.keyboardTypeDelay;
2595
2532
  const inputStrategy = opts?.inputStrategy;
2596
- const keyboardEventMode = opts?.mode === 'local' ? opts.keyboardEventMode : void 0;
2597
2533
  agent_tools_debug('Creating Computer agent with displayId:', displayId || 'primary');
2598
2534
  const agentOpts = {
2599
2535
  ...displayId ? {
@@ -2608,9 +2544,6 @@ class ComputerMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
2608
2544
  ...void 0 !== inputStrategy ? {
2609
2545
  inputStrategy
2610
2546
  } : {},
2611
- ...void 0 !== keyboardEventMode ? {
2612
- keyboardEventMode
2613
- } : {},
2614
2547
  ...this.options.keepXvfbAliveUntilProcessExit ? {
2615
2548
  keepXvfbAliveUntilProcessExit: true
2616
2549
  } : {},
@@ -2695,7 +2628,7 @@ const tools = new ComputerMidsceneTools({
2695
2628
  });
2696
2629
  (0, cli_namespaceObject.runToolsCLI)(tools, 'midscene-computer', {
2697
2630
  stripPrefix: 'computer_',
2698
- version: "1.12.4-beta-20260904041024.0",
2631
+ version: "1.12.4",
2699
2632
  extraCommands: (0, core_namespaceObject.createReportCliCommands)()
2700
2633
  }).catch((e)=>{
2701
2634
  process.exit((0, cli_namespaceObject.reportCLIError)(e));