@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/index.js CHANGED
@@ -68,210 +68,6 @@ const img_namespaceObject = require("@midscene/shared/img");
68
68
  const logger_namespaceObject = require("@midscene/shared/logger");
69
69
  const external_screenshot_desktop_namespaceObject = require("screenshot-desktop");
70
70
  var external_screenshot_desktop_default = /*#__PURE__*/ __webpack_require__.n(external_screenshot_desktop_namespaceObject);
71
- const US_SHIFTED_CHARACTER_KEYS = new Map([
72
- [
73
- '~',
74
- '`'
75
- ],
76
- [
77
- '!',
78
- '1'
79
- ],
80
- [
81
- '@',
82
- '2'
83
- ],
84
- [
85
- '#',
86
- '3'
87
- ],
88
- [
89
- '$',
90
- '4'
91
- ],
92
- [
93
- '%',
94
- '5'
95
- ],
96
- [
97
- '^',
98
- '6'
99
- ],
100
- [
101
- '&',
102
- '7'
103
- ],
104
- [
105
- '*',
106
- '8'
107
- ],
108
- [
109
- '(',
110
- '9'
111
- ],
112
- [
113
- ')',
114
- '0'
115
- ],
116
- [
117
- '_',
118
- '-'
119
- ],
120
- [
121
- '+',
122
- '='
123
- ],
124
- [
125
- '{',
126
- '['
127
- ],
128
- [
129
- '}',
130
- ']'
131
- ],
132
- [
133
- '|',
134
- '\\'
135
- ],
136
- [
137
- ':',
138
- ';'
139
- ],
140
- [
141
- '"',
142
- "'"
143
- ],
144
- [
145
- '<',
146
- ','
147
- ],
148
- [
149
- '>',
150
- '.'
151
- ],
152
- [
153
- '?',
154
- '/'
155
- ]
156
- ]);
157
- const debugKeyboard = (0, logger_namespaceObject.getDebug)('computer:keyboard');
158
- const APPLE_SCRIPT_KEY_CODES = {
159
- return: 36,
160
- enter: 36,
161
- tab: 48,
162
- space: 49,
163
- backspace: 51,
164
- delete: 51,
165
- escape: 53,
166
- forwarddelete: 117,
167
- left: 123,
168
- right: 124,
169
- down: 125,
170
- up: 126,
171
- home: 115,
172
- end: 119,
173
- pageup: 116,
174
- pagedown: 121,
175
- f1: 122,
176
- f2: 120,
177
- f3: 99,
178
- f4: 118,
179
- f5: 96,
180
- f6: 97,
181
- f7: 98,
182
- f8: 100,
183
- f9: 101,
184
- f10: 109,
185
- f11: 103,
186
- f12: 111
187
- };
188
- const APPLE_SCRIPT_MODIFIER_KEYS = {
189
- command: 'command',
190
- cmd: 'command',
191
- control: 'control',
192
- ctrl: 'control',
193
- shift: 'shift',
194
- alt: 'option',
195
- option: 'option',
196
- meta: 'command'
197
- };
198
- function buildKeyCommand(key) {
199
- const keyCode = APPLE_SCRIPT_KEY_CODES[key.toLowerCase()];
200
- if (void 0 !== keyCode) return `key code ${keyCode}`;
201
- const escapedKey = key.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
202
- return `keystroke "${escapedKey}"`;
203
- }
204
- function resolveModifierKeys(modifiers) {
205
- return modifiers.map((modifier)=>APPLE_SCRIPT_MODIFIER_KEYS[modifier.toLowerCase()]).filter((modifier)=>void 0 !== modifier);
206
- }
207
- function buildLogicalKeyPress(key, modifiers) {
208
- const modifierKeys = resolveModifierKeys(modifiers);
209
- const modifierClause = modifierKeys.length ? ` using {${modifierKeys.map((modifier)=>`${modifier} down`).join(', ')}}` : '';
210
- return `tell application "System Events" to ${buildKeyCommand(key)}${modifierClause}`;
211
- }
212
- function resolvePhysicalKey(key, modifiers) {
213
- const resolvedModifiers = [
214
- ...modifiers
215
- ];
216
- const shiftedBaseKey = US_SHIFTED_CHARACTER_KEYS.get(key);
217
- if (/^[A-Z]$/.test(key)) {
218
- resolvedModifiers.push('shift');
219
- return {
220
- key: key.toLowerCase(),
221
- modifiers: resolvedModifiers
222
- };
223
- }
224
- if (void 0 !== shiftedBaseKey) {
225
- resolvedModifiers.push('shift');
226
- return {
227
- key: shiftedBaseKey,
228
- modifiers: resolvedModifiers
229
- };
230
- }
231
- return {
232
- key,
233
- modifiers: resolvedModifiers
234
- };
235
- }
236
- function buildPhysicalKeyPress(key, modifiers) {
237
- const resolved = resolvePhysicalKey(key, modifiers);
238
- const modifierKeys = [
239
- ...new Set(resolveModifierKeys(resolved.modifiers))
240
- ];
241
- const keyCommand = buildKeyCommand(resolved.key);
242
- if (0 === modifierKeys.length) return `tell application "System Events" to ${keyCommand}`;
243
- const releaseCommands = [
244
- ...modifierKeys
245
- ].reverse().map((modifier)=>`key up ${modifier}`);
246
- return [
247
- 'tell application "System Events"',
248
- 'try',
249
- ...modifierKeys.map((modifier)=>`key down ${modifier}`),
250
- keyCommand,
251
- 'on error errorMessage number errorNumber',
252
- ...releaseCommands,
253
- 'error errorMessage number errorNumber',
254
- 'end try',
255
- ...releaseCommands,
256
- 'end tell'
257
- ].join('\n');
258
- }
259
- function buildAppleScriptKeyPress(key, modifiers = [], eventMode = 'logical') {
260
- return 'physical' === eventMode ? buildPhysicalKeyPress(key, modifiers) : buildLogicalKeyPress(key, modifiers);
261
- }
262
- function sendKeyViaAppleScript(key, modifiers = [], eventMode = 'logical') {
263
- const script = buildAppleScriptKeyPress(key, modifiers, eventMode);
264
- debugKeyboard('sendKeyViaAppleScript', {
265
- key,
266
- modifiers,
267
- eventMode,
268
- script
269
- });
270
- (0, external_node_child_process_namespaceObject.execFileSync)("osascript", [
271
- '-e',
272
- script
273
- ]);
274
- }
275
71
  const external_node_assert_namespaceObject = require("node:assert");
276
72
  var external_node_assert_default = /*#__PURE__*/ __webpack_require__.n(external_node_assert_namespaceObject);
277
73
  function _define_property(obj, key, value) {
@@ -797,6 +593,92 @@ const LIBNUT_FALLBACK_PIXELS_PER_DETENT = 100;
797
593
  const LIBNUT_FALLBACK_TICK_DELAY_MS = 30;
798
594
  const LIBNUT_FALLBACK_MAX_DETENTS = 200;
799
595
  const LIBNUT_FALLBACK_DETENT_AMOUNT = 'win32' === process.platform ? 120 : 1;
596
+ const LINUX_SHIFTED_CHARACTER_KEYS = new Map([
597
+ [
598
+ '~',
599
+ '`'
600
+ ],
601
+ [
602
+ '!',
603
+ '1'
604
+ ],
605
+ [
606
+ '@',
607
+ '2'
608
+ ],
609
+ [
610
+ '#',
611
+ '3'
612
+ ],
613
+ [
614
+ '$',
615
+ '4'
616
+ ],
617
+ [
618
+ '%',
619
+ '5'
620
+ ],
621
+ [
622
+ '^',
623
+ '6'
624
+ ],
625
+ [
626
+ '&',
627
+ '7'
628
+ ],
629
+ [
630
+ '*',
631
+ '8'
632
+ ],
633
+ [
634
+ '(',
635
+ '9'
636
+ ],
637
+ [
638
+ ')',
639
+ '0'
640
+ ],
641
+ [
642
+ '_',
643
+ '-'
644
+ ],
645
+ [
646
+ '+',
647
+ '='
648
+ ],
649
+ [
650
+ '{',
651
+ '['
652
+ ],
653
+ [
654
+ '}',
655
+ ']'
656
+ ],
657
+ [
658
+ '|',
659
+ '\\'
660
+ ],
661
+ [
662
+ ':',
663
+ ';'
664
+ ],
665
+ [
666
+ '"',
667
+ "'"
668
+ ],
669
+ [
670
+ '<',
671
+ ','
672
+ ],
673
+ [
674
+ '>',
675
+ '.'
676
+ ],
677
+ [
678
+ '?',
679
+ '/'
680
+ ]
681
+ ]);
800
682
  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)));
801
683
  const DEFAULT_SCROLL_VIEWPORT_RATIO = 0.7;
802
684
  const EDGE_SCROLL_SPEC = {
@@ -833,6 +715,67 @@ const EDGE_SCROLL_SPEC = {
833
715
  ]
834
716
  }
835
717
  };
718
+ const APPLESCRIPT_KEY_CODE_MAP = {
719
+ return: 36,
720
+ enter: 36,
721
+ tab: 48,
722
+ space: 49,
723
+ backspace: 51,
724
+ delete: 51,
725
+ escape: 53,
726
+ forwarddelete: 117,
727
+ left: 123,
728
+ right: 124,
729
+ down: 125,
730
+ up: 126,
731
+ home: 115,
732
+ end: 119,
733
+ pageup: 116,
734
+ pagedown: 121,
735
+ f1: 122,
736
+ f2: 120,
737
+ f3: 99,
738
+ f4: 118,
739
+ f5: 96,
740
+ f6: 97,
741
+ f7: 98,
742
+ f8: 100,
743
+ f9: 101,
744
+ f10: 109,
745
+ f11: 103,
746
+ f12: 111
747
+ };
748
+ const APPLESCRIPT_MODIFIER_MAP = {
749
+ command: 'command down',
750
+ cmd: 'command down',
751
+ control: 'control down',
752
+ ctrl: 'control down',
753
+ shift: 'shift down',
754
+ alt: 'option down',
755
+ option: 'option down',
756
+ meta: 'command down'
757
+ };
758
+ function sendKeyViaAppleScript(key, modifiers = []) {
759
+ const lowerKey = key.toLowerCase();
760
+ const keyCode = APPLESCRIPT_KEY_CODE_MAP[lowerKey];
761
+ const modifierParts = modifiers.map((m)=>APPLESCRIPT_MODIFIER_MAP[m.toLowerCase()]).filter(Boolean);
762
+ const modifierStr = modifierParts.length > 0 ? ` using {${modifierParts.join(', ')}}` : '';
763
+ let script;
764
+ if (void 0 !== keyCode) script = `tell application "System Events" to key code ${keyCode}${modifierStr}`;
765
+ else {
766
+ const escapedKey = key.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
767
+ script = `tell application "System Events" to keystroke "${escapedKey}"${modifierStr}`;
768
+ }
769
+ debugDevice('sendKeyViaAppleScript', {
770
+ key,
771
+ modifiers,
772
+ script
773
+ });
774
+ (0, external_node_child_process_namespaceObject.execFileSync)("osascript", [
775
+ '-e',
776
+ script
777
+ ]);
778
+ }
836
779
  function escapePowershellSingleQuoted(value) {
837
780
  return value.replace(/'/g, "''");
838
781
  }
@@ -1260,7 +1203,7 @@ Available Displays: ${displays.length > 0 ? displays.map((d)=>d.name).join(', ')
1260
1203
  }
1261
1204
  async healthCheck(displays) {
1262
1205
  console.log('[HealthCheck] Starting health check...');
1263
- console.log("[HealthCheck] @midscene/computer v1.12.4-beta-20260904041024.0");
1206
+ console.log("[HealthCheck] @midscene/computer v1.12.4");
1264
1207
  console.log('[HealthCheck] Taking screenshot...');
1265
1208
  const screenshotTimeout = 15000;
1266
1209
  let timeoutId;
@@ -1455,7 +1398,7 @@ $g.Dispose(); $bmp.Dispose(); $ms.Dispose()
1455
1398
  async typeStringWithDelay(text, keyboardTypeDelay) {
1456
1399
  await (0, device_namespaceObject.sendTextSequentially)(text.replace(/\r\n?/g, '\n'), {
1457
1400
  sendCharacter: (character)=>{
1458
- const linuxShiftedKey = 'linux' === process.platform ? US_SHIFTED_CHARACTER_KEYS.get(character) : void 0;
1401
+ const linuxShiftedKey = 'linux' === process.platform ? LINUX_SHIFTED_CHARACTER_KEYS.get(character) : void 0;
1459
1402
  if ('\n' === character) this.inputDriver.sendKey('return');
1460
1403
  else if ('\t' === character) this.inputDriver.sendKey('tab');
1461
1404
  else if (' ' === character) this.inputDriver.sendKey('space');
@@ -1649,7 +1592,7 @@ $g.Dispose(); $bmp.Dispose(); $ms.Dispose()
1649
1592
  device_define_property(this, "inputDriver", new ComputerInputDriver({
1650
1593
  getLibnut: ()=>device_libnut,
1651
1594
  useAppleScript: ()=>this.useAppleScript,
1652
- sendKeyViaAppleScript: (key, modifiers)=>sendKeyViaAppleScript(key, modifiers, this.options?.keyboardEventMode ?? 'logical'),
1595
+ sendKeyViaAppleScript,
1653
1596
  runPhasedScroll,
1654
1597
  debug: (message)=>debugDevice(message)
1655
1598
  }));
@@ -2519,7 +2462,6 @@ function createLocalComputerDevice(opts) {
2519
2462
  keyboardTypeDelay: opts?.keyboardTypeDelay,
2520
2463
  inputStrategy: opts?.inputStrategy,
2521
2464
  keyboardDriver: opts?.keyboardDriver,
2522
- keyboardEventMode: opts?.keyboardEventMode,
2523
2465
  headless: opts?.headless,
2524
2466
  xvfbResolution: opts?.xvfbResolution,
2525
2467
  keepXvfbAliveUntilProcessExit: opts?.keepXvfbAliveUntilProcessExit
@@ -2580,10 +2522,6 @@ const computerInitArgShape = {
2580
2522
  headless: core_namespaceObject.z.boolean().optional().describe('Start virtual display via Xvfb (Linux local mode only). Ignored when host is set.'),
2581
2523
  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.'),
2582
2524
  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.'),
2583
- keyboardEventMode: core_namespaceObject.z["enum"]([
2584
- 'logical',
2585
- 'physical'
2586
- ]).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.'),
2587
2525
  host: core_namespaceObject.z.string().optional().describe('RDP host (FQDN or IP). Set this to switch into RDP mode.'),
2588
2526
  port: core_namespaceObject.z.number().optional().describe('RDP port (default 3389). Requires host.'),
2589
2527
  username: core_namespaceObject.z.string().optional().describe('RDP username. Requires host.'),
@@ -2600,7 +2538,7 @@ const computerInitArgShape = {
2600
2538
  function adaptComputerInitArgs(extracted) {
2601
2539
  if (!extracted || 0 === Object.keys(extracted).length) return;
2602
2540
  if (extracted.host) {
2603
- const { displayId: _d, headless: _h, keyboardEventMode: _k, ...rdpFields } = extracted;
2541
+ const { displayId: _d, headless: _h, ...rdpFields } = extracted;
2604
2542
  const host = normalizeRdpHost(extracted.host);
2605
2543
  return {
2606
2544
  mode: 'rdp',
@@ -2614,7 +2552,6 @@ function adaptComputerInitArgs(extracted) {
2614
2552
  headless: extracted.headless,
2615
2553
  keyboardTypeDelay: extracted.keyboardTypeDelay,
2616
2554
  inputStrategy: extracted.inputStrategy,
2617
- keyboardEventMode: extracted.keyboardEventMode,
2618
2555
  ...(0, agent_behavior_init_args_namespaceObject.extractAgentBehaviorInitArgs)(extracted) ?? {}
2619
2556
  };
2620
2557
  }
@@ -2666,7 +2603,6 @@ class ComputerMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
2666
2603
  const headless = opts?.mode === 'local' ? opts.headless : void 0;
2667
2604
  const keyboardTypeDelay = opts?.keyboardTypeDelay;
2668
2605
  const inputStrategy = opts?.inputStrategy;
2669
- const keyboardEventMode = opts?.mode === 'local' ? opts.keyboardEventMode : void 0;
2670
2606
  agent_tools_debug('Creating Computer agent with displayId:', displayId || 'primary');
2671
2607
  const agentOpts = {
2672
2608
  ...displayId ? {
@@ -2681,9 +2617,6 @@ class ComputerMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
2681
2617
  ...void 0 !== inputStrategy ? {
2682
2618
  inputStrategy
2683
2619
  } : {},
2684
- ...void 0 !== keyboardEventMode ? {
2685
- keyboardEventMode
2686
- } : {},
2687
2620
  ...this.options.keepXvfbAliveUntilProcessExit ? {
2688
2621
  keepXvfbAliveUntilProcessExit: true
2689
2622
  } : {},
@@ -2765,7 +2698,7 @@ class ComputerMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
2765
2698
  }
2766
2699
  const env_namespaceObject = require("@midscene/shared/env");
2767
2700
  function version() {
2768
- const currentVersion = "1.12.4-beta-20260904041024.0";
2701
+ const currentVersion = "1.12.4";
2769
2702
  console.log(`@midscene/computer v${currentVersion}`);
2770
2703
  return currentVersion;
2771
2704
  }
@@ -177,19 +177,6 @@ export declare interface ComputerDeviceOpt extends ComputerDeviceInputOpt {
177
177
  * - 'libnut': Use libnut's keyTap (faster but may not work with some TUI apps)
178
178
  */
179
179
  keyboardDriver?: 'applescript' | 'libnut';
180
- /**
181
- * How the macOS AppleScript keyboard driver represents modifier keys.
182
- * `logical` keeps the default compact `keystroke ... using` behavior.
183
- * `physical` emits explicit modifier key-down/key-up transitions for apps
184
- * such as VNC clients that forward physical keyboard events. Physical mode
185
- * assumes an en-US layout for shifted punctuation and may type base keys in
186
- * native macOS applications. Text input must use sequential input or a
187
- * positive `keyboardTypeDelay` to emit individual keys.
188
- *
189
- * Ignored outside macOS and when `keyboardDriver` is `libnut`.
190
- * @default 'logical'
191
- */
192
- keyboardEventMode?: KeyboardEventMode;
193
180
  /**
194
181
  * Headless mode via Xvfb (Linux only).
195
182
  * - true: start Xvfb virtual display
@@ -223,7 +210,7 @@ export declare type ComputerInterface = ComputerDevice | RDPDevice;
223
210
  /** Init args for the local desktop agent (macOS/Windows/Linux). */
224
211
  declare type ComputerLocalInitArgs = {
225
212
  mode: 'local';
226
- } & Pick<ComputerDeviceOpt, 'displayId' | 'headless'> & Pick<ComputerDeviceOpt, 'inputStrategy' | 'keyboardTypeDelay' | 'keyboardEventMode'> & AgentBehaviorInitArgs;
213
+ } & Pick<ComputerDeviceOpt, 'displayId' | 'headless'> & Pick<ComputerDeviceOpt, 'inputStrategy' | 'keyboardTypeDelay'> & AgentBehaviorInitArgs;
227
214
 
228
215
  /**
229
216
  * Computer-specific tools manager
@@ -310,15 +297,6 @@ export declare class HelperProcessRDPBackendClient implements RDPBackendClient {
310
297
  private shutdownHelper;
311
298
  }
312
299
 
313
- /**
314
- * Modifier delivery mode for the macOS AppleScript keyboard backend.
315
- *
316
- * `logical` is the default for native macOS applications. `physical` emits
317
- * explicit modifier transitions for VNC clients and assumes an en-US mapping
318
- * for shifted punctuation; it should not be enabled for native applications.
319
- */
320
- export declare type KeyboardEventMode = 'logical' | 'physical';
321
-
322
300
  export declare type LocalComputerAgentOpt = BaseComputerAgentOpt & Omit<ComputerDeviceOpt, keyof ComputerAgentSharedDeviceOpt>;
323
301
 
324
302
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midscene/computer",
3
- "version": "1.12.4-beta-20260904041024.0",
3
+ "version": "1.12.4",
4
4
  "description": "Midscene.js Computer Desktop Automation",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -33,8 +33,8 @@
33
33
  "@computer-use/libnut": "^4.2.0",
34
34
  "clipboardy": "^4.0.0",
35
35
  "screenshot-desktop": "^1.15.3",
36
- "@midscene/core": "1.12.4-beta-20260904041024.0",
37
- "@midscene/shared": "1.12.4-beta-20260904041024.0"
36
+ "@midscene/core": "1.12.4",
37
+ "@midscene/shared": "1.12.4"
38
38
  },
39
39
  "optionalDependencies": {
40
40
  "node-mac-permissions": "2.5.0"