@namzu/computer-use 1.4.3 → 2.0.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/CHANGELOG.md +36 -0
- package/README.md +96 -5
- package/dist/SubprocessComputerUseHost.d.ts +45 -5
- package/dist/SubprocessComputerUseHost.d.ts.map +1 -1
- package/dist/SubprocessComputerUseHost.js +94 -8
- package/dist/SubprocessComputerUseHost.js.map +1 -1
- package/dist/adapters/cua-driver/adapter.d.ts +100 -0
- package/dist/adapters/cua-driver/adapter.d.ts.map +1 -0
- package/dist/adapters/cua-driver/adapter.js +459 -0
- package/dist/adapters/cua-driver/adapter.js.map +1 -0
- package/dist/adapters/cua-driver/client.d.ts +108 -0
- package/dist/adapters/cua-driver/client.d.ts.map +1 -0
- package/dist/adapters/cua-driver/client.js +316 -0
- package/dist/adapters/cua-driver/client.js.map +1 -0
- package/dist/adapters/cua-driver/keys.d.ts +24 -0
- package/dist/adapters/cua-driver/keys.d.ts.map +1 -0
- package/dist/adapters/cua-driver/keys.js +106 -0
- package/dist/adapters/cua-driver/keys.js.map +1 -0
- package/dist/adapters/cua-driver/provision.d.ts +80 -0
- package/dist/adapters/cua-driver/provision.d.ts.map +1 -0
- package/dist/adapters/cua-driver/provision.js +147 -0
- package/dist/adapters/cua-driver/provision.js.map +1 -0
- package/dist/adapters/cua-driver/ui-tree.d.ts +42 -0
- package/dist/adapters/cua-driver/ui-tree.d.ts.map +1 -0
- package/dist/adapters/cua-driver/ui-tree.js +187 -0
- package/dist/adapters/cua-driver/ui-tree.js.map +1 -0
- package/dist/adapters/cua-driver/zip.d.ts +6 -0
- package/dist/adapters/cua-driver/zip.d.ts.map +1 -0
- package/dist/adapters/cua-driver/zip.js +86 -0
- package/dist/adapters/cua-driver/zip.js.map +1 -0
- package/dist/adapters/darwin.d.ts +23 -0
- package/dist/adapters/darwin.d.ts.map +1 -1
- package/dist/adapters/darwin.js +96 -31
- package/dist/adapters/darwin.js.map +1 -1
- package/dist/adapters/linux-wayland.d.ts.map +1 -1
- package/dist/adapters/linux-wayland.js +12 -0
- package/dist/adapters/linux-wayland.js.map +1 -1
- package/dist/adapters/linux-x11.d.ts.map +1 -1
- package/dist/adapters/linux-x11.js +12 -0
- package/dist/adapters/linux-x11.js.map +1 -1
- package/dist/adapters/types.d.ts +23 -5
- package/dist/adapters/types.d.ts.map +1 -1
- package/dist/adapters/types.js.map +1 -1
- package/dist/adapters/win32-powershell.d.ts +41 -0
- package/dist/adapters/win32-powershell.d.ts.map +1 -0
- package/dist/adapters/win32-powershell.js +407 -0
- package/dist/adapters/win32-powershell.js.map +1 -0
- package/dist/adapters/win32.d.ts +39 -11
- package/dist/adapters/win32.d.ts.map +1 -1
- package/dist/adapters/win32.js +72 -311
- package/dist/adapters/win32.js.map +1 -1
- package/dist/adapters/wsl.d.ts +46 -0
- package/dist/adapters/wsl.d.ts.map +1 -0
- package/dist/adapters/wsl.js +130 -0
- package/dist/adapters/wsl.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/SubprocessComputerUseHost.ts +115 -8
- package/src/adapters/cua-driver/adapter.ts +571 -0
- package/src/adapters/cua-driver/client.ts +451 -0
- package/src/adapters/cua-driver/keys.ts +111 -0
- package/src/adapters/cua-driver/provision.ts +208 -0
- package/src/adapters/cua-driver/ui-tree.ts +234 -0
- package/src/adapters/cua-driver/zip.ts +90 -0
- package/src/adapters/darwin.ts +124 -38
- package/src/adapters/linux-wayland.ts +13 -0
- package/src/adapters/linux-x11.ts +13 -0
- package/src/adapters/types.ts +29 -4
- package/src/adapters/win32-powershell.ts +482 -0
- package/src/adapters/win32.ts +112 -356
- package/src/adapters/wsl.ts +150 -0
- package/src/index.ts +5 -1
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
import { hasExecutable, runCommandOrThrow } from '../util/spawn.js';
|
|
2
|
+
import { AdapterUnavailableError } from './types.js';
|
|
3
|
+
import { isWsl, realWslProbes, wslChildEnv, wslPowerShellPath } from './wsl.js';
|
|
4
|
+
/**
|
|
5
|
+
* The Windows fallback: one `powershell.exe` per action, as this package has
|
|
6
|
+
* always done. It is used when cua-driver cannot be (see `./win32.ts`), so it
|
|
7
|
+
* keeps the host contract — physical pixels, the captured display described
|
|
8
|
+
* — and nothing more: no window list, and a new process (about 0.3–0.8 s)
|
|
9
|
+
* for every action.
|
|
10
|
+
*/
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
// Key translation: our input ("ctrl+c") → PowerShell SendKeys format ("^c").
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
const SENDKEYS_MODIFIER = {
|
|
15
|
+
cmd: '^',
|
|
16
|
+
command: '^',
|
|
17
|
+
ctrl: '^',
|
|
18
|
+
control: '^',
|
|
19
|
+
meta: '^',
|
|
20
|
+
super: '^',
|
|
21
|
+
win: '^',
|
|
22
|
+
alt: '%',
|
|
23
|
+
option: '%',
|
|
24
|
+
opt: '%',
|
|
25
|
+
shift: '+',
|
|
26
|
+
};
|
|
27
|
+
const SENDKEYS_SPECIAL = {
|
|
28
|
+
enter: '{ENTER}',
|
|
29
|
+
return: '{ENTER}',
|
|
30
|
+
escape: '{ESC}',
|
|
31
|
+
esc: '{ESC}',
|
|
32
|
+
tab: '{TAB}',
|
|
33
|
+
backspace: '{BACKSPACE}',
|
|
34
|
+
delete: '{DELETE}',
|
|
35
|
+
forward_delete: '{DELETE}',
|
|
36
|
+
space: ' ',
|
|
37
|
+
up: '{UP}',
|
|
38
|
+
down: '{DOWN}',
|
|
39
|
+
left: '{LEFT}',
|
|
40
|
+
right: '{RIGHT}',
|
|
41
|
+
home: '{HOME}',
|
|
42
|
+
end: '{END}',
|
|
43
|
+
page_up: '{PGUP}',
|
|
44
|
+
page_down: '{PGDN}',
|
|
45
|
+
f1: '{F1}',
|
|
46
|
+
f2: '{F2}',
|
|
47
|
+
f3: '{F3}',
|
|
48
|
+
f4: '{F4}',
|
|
49
|
+
f5: '{F5}',
|
|
50
|
+
f6: '{F6}',
|
|
51
|
+
f7: '{F7}',
|
|
52
|
+
f8: '{F8}',
|
|
53
|
+
f9: '{F9}',
|
|
54
|
+
f10: '{F10}',
|
|
55
|
+
f11: '{F11}',
|
|
56
|
+
f12: '{F12}',
|
|
57
|
+
};
|
|
58
|
+
export function translateKeyToSendKeys(combo) {
|
|
59
|
+
const parts = combo
|
|
60
|
+
.split('+')
|
|
61
|
+
.map((p) => p.trim())
|
|
62
|
+
.filter((p) => p.length > 0);
|
|
63
|
+
if (parts.length === 0)
|
|
64
|
+
throw new Error('translateKeyToSendKeys: empty key combo');
|
|
65
|
+
const main = parts[parts.length - 1] ?? '';
|
|
66
|
+
const mods = parts.slice(0, -1);
|
|
67
|
+
const modifierPrefix = mods
|
|
68
|
+
.map((m) => {
|
|
69
|
+
const prefix = SENDKEYS_MODIFIER[m.toLowerCase()];
|
|
70
|
+
if (!prefix)
|
|
71
|
+
throw new Error(`translateKeyToSendKeys: unknown modifier "${m}"`);
|
|
72
|
+
return prefix;
|
|
73
|
+
})
|
|
74
|
+
.join('');
|
|
75
|
+
const special = SENDKEYS_SPECIAL[main.toLowerCase()];
|
|
76
|
+
if (special)
|
|
77
|
+
return modifierPrefix + special;
|
|
78
|
+
// Single printable chars pass through as-is; longer names stay literal and
|
|
79
|
+
// SendKeys will fall back to per-character typing.
|
|
80
|
+
return modifierPrefix + main;
|
|
81
|
+
}
|
|
82
|
+
// ---------------------------------------------------------------------------
|
|
83
|
+
// One PowerShell invocation per action. The script travels as
|
|
84
|
+
// `-EncodedCommand` (UTF-16LE base64), so no character of it — and none of
|
|
85
|
+
// the text being typed — reaches a command-line parser.
|
|
86
|
+
// ---------------------------------------------------------------------------
|
|
87
|
+
/** PowerShell's `-EncodedCommand` form: the script as UTF-16LE, base64. */
|
|
88
|
+
export function encodePowerShellCommand(script) {
|
|
89
|
+
return Buffer.from(script, 'utf16le').toString('base64');
|
|
90
|
+
}
|
|
91
|
+
export function powerShellArguments(script) {
|
|
92
|
+
return [
|
|
93
|
+
'-NoLogo',
|
|
94
|
+
'-NoProfile',
|
|
95
|
+
'-NonInteractive',
|
|
96
|
+
'-ExecutionPolicy',
|
|
97
|
+
'Bypass',
|
|
98
|
+
'-EncodedCommand',
|
|
99
|
+
encodePowerShellCommand(`$ProgressPreference = 'SilentlyContinue'\n${script}`),
|
|
100
|
+
];
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Compiled into every invocation, and the first thing each one runs: the
|
|
104
|
+
* process becomes per-monitor DPI aware (V2, then the Windows 8.1 API, then
|
|
105
|
+
* the Vista one) before it reads a bound, captures or moves anything, so
|
|
106
|
+
* all of those are physical pixels. Without it a display at 150 % reported
|
|
107
|
+
* two thirds of its size and the capture showed only its top-left part.
|
|
108
|
+
*/
|
|
109
|
+
const DESKTOP_TYPE = `
|
|
110
|
+
if (-not ([System.Management.Automation.PSTypeName]'Namzu.Desktop').Type) {
|
|
111
|
+
Add-Type -TypeDefinition @"
|
|
112
|
+
using System;
|
|
113
|
+
using System.Runtime.InteropServices;
|
|
114
|
+
namespace Namzu {
|
|
115
|
+
public static class Desktop {
|
|
116
|
+
[DllImport("user32.dll")] static extern bool SetProcessDpiAwarenessContext(IntPtr value);
|
|
117
|
+
[DllImport("shcore.dll")] static extern int SetProcessDpiAwareness(int value);
|
|
118
|
+
[DllImport("user32.dll")] static extern bool SetProcessDPIAware();
|
|
119
|
+
[DllImport("user32.dll")] static extern IntPtr MonitorFromPoint(POINT pt, uint flags);
|
|
120
|
+
[DllImport("shcore.dll")] static extern int GetDpiForMonitor(IntPtr monitor, int type, out uint x, out uint y);
|
|
121
|
+
[StructLayout(LayoutKind.Sequential)] public struct POINT { public int X; public int Y; }
|
|
122
|
+
[StructLayout(LayoutKind.Sequential)]
|
|
123
|
+
public struct MOUSEINPUT { public int dx; public int dy; public uint mouseData; public uint dwFlags; public uint time; public IntPtr dwExtraInfo; }
|
|
124
|
+
[StructLayout(LayoutKind.Sequential)]
|
|
125
|
+
public struct KEYBDINPUT { public ushort wVk; public ushort wScan; public uint dwFlags; public uint time; public IntPtr dwExtraInfo; }
|
|
126
|
+
[StructLayout(LayoutKind.Explicit)]
|
|
127
|
+
public struct INPUTUNION { [FieldOffset(0)] public MOUSEINPUT mi; [FieldOffset(0)] public KEYBDINPUT ki; }
|
|
128
|
+
[StructLayout(LayoutKind.Sequential)]
|
|
129
|
+
public struct INPUT { public uint type; public INPUTUNION u; }
|
|
130
|
+
[DllImport("user32.dll", SetLastError = true)] static extern uint SendInput(uint n, INPUT[] inputs, int size);
|
|
131
|
+
[DllImport("user32.dll")] public static extern bool SetCursorPos(int x, int y);
|
|
132
|
+
public static void MakeDpiAware() {
|
|
133
|
+
try { if (SetProcessDpiAwarenessContext(new IntPtr(-4))) return; } catch (Exception) {}
|
|
134
|
+
try { if (SetProcessDpiAwareness(2) == 0) return; } catch (Exception) {}
|
|
135
|
+
try { SetProcessDPIAware(); } catch (Exception) {}
|
|
136
|
+
}
|
|
137
|
+
public static double PrimaryScale() {
|
|
138
|
+
try {
|
|
139
|
+
uint x, y;
|
|
140
|
+
IntPtr monitor = MonitorFromPoint(new POINT(), 1);
|
|
141
|
+
if (GetDpiForMonitor(monitor, 0, out x, out y) == 0 && x > 0) return x / 96.0;
|
|
142
|
+
} catch (Exception) {}
|
|
143
|
+
return 1.0;
|
|
144
|
+
}
|
|
145
|
+
static INPUT Mouse(uint flags, uint data) {
|
|
146
|
+
INPUT input = new INPUT(); input.type = 0; input.u.mi.dwFlags = flags; input.u.mi.mouseData = data; return input;
|
|
147
|
+
}
|
|
148
|
+
static INPUT Key(ushort vk, ushort scan, uint flags) {
|
|
149
|
+
INPUT input = new INPUT(); input.type = 1; input.u.ki.wVk = vk; input.u.ki.wScan = scan; input.u.ki.dwFlags = flags; return input;
|
|
150
|
+
}
|
|
151
|
+
static void Send(params INPUT[] inputs) {
|
|
152
|
+
SendInput((uint)inputs.Length, inputs, Marshal.SizeOf(typeof(INPUT)));
|
|
153
|
+
}
|
|
154
|
+
public static void MouseEvent(uint flags, uint data) { Send(Mouse(flags, data)); }
|
|
155
|
+
public static void Click(uint down, uint up) { Send(Mouse(down, 0), Mouse(up, 0)); }
|
|
156
|
+
public static void TypeText(string text) {
|
|
157
|
+
for (int i = 0; i < text.Length; i++) {
|
|
158
|
+
char c = text[i];
|
|
159
|
+
if (c == '\\r' && i + 1 < text.Length && text[i + 1] == '\\n') continue;
|
|
160
|
+
if (c == '\\r' || c == '\\n') { Send(Key(0x0D, 0, 0), Key(0x0D, 0, 2)); continue; }
|
|
161
|
+
if (c == '\\t') { Send(Key(0x09, 0, 0), Key(0x09, 0, 2)); continue; }
|
|
162
|
+
// KEYEVENTF_UNICODE: the character itself, whatever the keyboard layout.
|
|
163
|
+
Send(Key(0, c, 4), Key(0, c, 4 | 2));
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
"@
|
|
169
|
+
}
|
|
170
|
+
[Namzu.Desktop]::MakeDpiAware()
|
|
171
|
+
`.trim();
|
|
172
|
+
const MOUSEEVENTF = {
|
|
173
|
+
leftDown: 0x0002,
|
|
174
|
+
leftUp: 0x0004,
|
|
175
|
+
rightDown: 0x0008,
|
|
176
|
+
rightUp: 0x0010,
|
|
177
|
+
middleDown: 0x0020,
|
|
178
|
+
middleUp: 0x0040,
|
|
179
|
+
wheel: 0x0800,
|
|
180
|
+
hwheel: 0x01000,
|
|
181
|
+
};
|
|
182
|
+
const MOUSE_DOWN_UP = {
|
|
183
|
+
left: [MOUSEEVENTF.leftDown, MOUSEEVENTF.leftUp],
|
|
184
|
+
right: [MOUSEEVENTF.rightDown, MOUSEEVENTF.rightUp],
|
|
185
|
+
middle: [MOUSEEVENTF.middleDown, MOUSEEVENTF.middleUp],
|
|
186
|
+
};
|
|
187
|
+
/** The primary display, physical. The primary display's origin is (0, 0) by definition. */
|
|
188
|
+
const DISPLAY_JSON = `
|
|
189
|
+
Add-Type -AssemblyName System.Windows.Forms
|
|
190
|
+
$b = [System.Windows.Forms.Screen]::PrimaryScreen.Bounds
|
|
191
|
+
$display = @{ x = $b.X; y = $b.Y; width = $b.Width; height = $b.Height; scaleFactor = [Namzu.Desktop]::PrimaryScale() }
|
|
192
|
+
`.trim();
|
|
193
|
+
const GEOMETRY_SCRIPT = `
|
|
194
|
+
${DESKTOP_TYPE}
|
|
195
|
+
${DISPLAY_JSON}
|
|
196
|
+
[Console]::Out.Write(($display | ConvertTo-Json -Compress))
|
|
197
|
+
`.trim();
|
|
198
|
+
const SCREENSHOT_SCRIPT = `
|
|
199
|
+
${DESKTOP_TYPE}
|
|
200
|
+
${DISPLAY_JSON}
|
|
201
|
+
Add-Type -AssemblyName System.Drawing
|
|
202
|
+
$bmp = New-Object System.Drawing.Bitmap $b.Width, $b.Height
|
|
203
|
+
$g = [System.Drawing.Graphics]::FromImage($bmp)
|
|
204
|
+
$g.CopyFromScreen($b.Location, [System.Drawing.Point]::Empty, $b.Size)
|
|
205
|
+
$ms = New-Object System.IO.MemoryStream
|
|
206
|
+
$bmp.Save($ms, [System.Drawing.Imaging.ImageFormat]::Png)
|
|
207
|
+
$g.Dispose()
|
|
208
|
+
$bmp.Dispose()
|
|
209
|
+
$display.png = [Convert]::ToBase64String($ms.ToArray())
|
|
210
|
+
[Console]::Out.Write(($display | ConvertTo-Json -Compress))
|
|
211
|
+
`.trim();
|
|
212
|
+
const CURSOR_POSITION_SCRIPT = `
|
|
213
|
+
${DESKTOP_TYPE}
|
|
214
|
+
Add-Type -AssemblyName System.Windows.Forms
|
|
215
|
+
$p = [System.Windows.Forms.Cursor]::Position
|
|
216
|
+
[Console]::Out.Write((@{ x = $p.X; y = $p.Y } | ConvertTo-Json -Compress))
|
|
217
|
+
`.trim();
|
|
218
|
+
function mouseClickScript(at, button) {
|
|
219
|
+
const [down, up] = MOUSE_DOWN_UP[button];
|
|
220
|
+
return `
|
|
221
|
+
${DESKTOP_TYPE}
|
|
222
|
+
[Namzu.Desktop]::SetCursorPos(${at.x}, ${at.y}) | Out-Null
|
|
223
|
+
[Namzu.Desktop]::Click(${down}, ${up})
|
|
224
|
+
`.trim();
|
|
225
|
+
}
|
|
226
|
+
function mouseMoveScript(to) {
|
|
227
|
+
return `
|
|
228
|
+
${DESKTOP_TYPE}
|
|
229
|
+
[Namzu.Desktop]::SetCursorPos(${to.x}, ${to.y}) | Out-Null
|
|
230
|
+
`.trim();
|
|
231
|
+
}
|
|
232
|
+
/** Press, move through intermediate points, release: many targets ignore a drag that teleports. */
|
|
233
|
+
export function dragPath(from, to, steps = 12) {
|
|
234
|
+
const path = [];
|
|
235
|
+
for (let i = 1; i <= steps; i++) {
|
|
236
|
+
path.push({
|
|
237
|
+
x: Math.round(from.x + ((to.x - from.x) * i) / steps),
|
|
238
|
+
y: Math.round(from.y + ((to.y - from.y) * i) / steps),
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
return path;
|
|
242
|
+
}
|
|
243
|
+
function mouseDragScript(from, to, button) {
|
|
244
|
+
const [down, up] = MOUSE_DOWN_UP[button];
|
|
245
|
+
const moves = dragPath(from, to)
|
|
246
|
+
.map((p) => `[Namzu.Desktop]::SetCursorPos(${p.x}, ${p.y}) | Out-Null; Start-Sleep -Milliseconds 15`)
|
|
247
|
+
.join('\n');
|
|
248
|
+
return `
|
|
249
|
+
${DESKTOP_TYPE}
|
|
250
|
+
[Namzu.Desktop]::SetCursorPos(${from.x}, ${from.y}) | Out-Null
|
|
251
|
+
[Namzu.Desktop]::MouseEvent(${down}, 0)
|
|
252
|
+
${moves}
|
|
253
|
+
[Namzu.Desktop]::MouseEvent(${up}, 0)
|
|
254
|
+
`.trim();
|
|
255
|
+
}
|
|
256
|
+
function scrollScript(at, direction, amount) {
|
|
257
|
+
const flag = direction === 'up' || direction === 'down' ? MOUSEEVENTF.wheel : MOUSEEVENTF.hwheel;
|
|
258
|
+
const sign = direction === 'up' || direction === 'right' ? 1 : -1;
|
|
259
|
+
const mouseData = (sign * 120 * amount) >>> 0; // WHEEL_DELTA * amount, as a DWORD
|
|
260
|
+
return `
|
|
261
|
+
${DESKTOP_TYPE}
|
|
262
|
+
[Namzu.Desktop]::SetCursorPos(${at.x}, ${at.y}) | Out-Null
|
|
263
|
+
[Namzu.Desktop]::MouseEvent(${flag}, ${mouseData})
|
|
264
|
+
`.trim();
|
|
265
|
+
}
|
|
266
|
+
/** The text crosses as base64 UTF-8 and is typed as Unicode key events, so layout and quoting cannot change it. */
|
|
267
|
+
function typeTextScript(text) {
|
|
268
|
+
const encoded = Buffer.from(text, 'utf8').toString('base64');
|
|
269
|
+
return `
|
|
270
|
+
${DESKTOP_TYPE}
|
|
271
|
+
[Namzu.Desktop]::TypeText([System.Text.Encoding]::UTF8.GetString([Convert]::FromBase64String('${encoded}')))
|
|
272
|
+
`.trim();
|
|
273
|
+
}
|
|
274
|
+
function pressKeyScript(combo) {
|
|
275
|
+
const sendKeys = translateKeyToSendKeys(combo);
|
|
276
|
+
return `
|
|
277
|
+
${DESKTOP_TYPE}
|
|
278
|
+
Add-Type -AssemblyName System.Windows.Forms
|
|
279
|
+
[System.Windows.Forms.SendKeys]::SendWait('${sendKeys.replace(/'/g, "''")}')
|
|
280
|
+
`.trim();
|
|
281
|
+
}
|
|
282
|
+
// ---------------------------------------------------------------------------
|
|
283
|
+
// Adapter
|
|
284
|
+
// ---------------------------------------------------------------------------
|
|
285
|
+
const POWERSHELL_CANDIDATES = ['pwsh', 'powershell', 'pwsh.exe', 'powershell.exe'];
|
|
286
|
+
async function findPowerShell(env, platform, probes) {
|
|
287
|
+
// Under WSL the Windows side's absolute path: PATH may not carry the
|
|
288
|
+
// Windows directories (appendWindowsPath=false, a systemd service).
|
|
289
|
+
if (isWsl(env, platform, probes)) {
|
|
290
|
+
const absolute = wslPowerShellPath(probes);
|
|
291
|
+
if (absolute)
|
|
292
|
+
return absolute;
|
|
293
|
+
}
|
|
294
|
+
const present = await Promise.all(POWERSHELL_CANDIDATES.map((name) => hasExecutable(name)));
|
|
295
|
+
return POWERSHELL_CANDIDATES.find((_name, index) => present[index]) ?? null;
|
|
296
|
+
}
|
|
297
|
+
export class Win32PowerShellAdapter {
|
|
298
|
+
powershell;
|
|
299
|
+
env;
|
|
300
|
+
fallbackReason;
|
|
301
|
+
capabilities;
|
|
302
|
+
backend = 'powershell';
|
|
303
|
+
constructor(powershell, env, fallbackReason) {
|
|
304
|
+
this.powershell = powershell;
|
|
305
|
+
this.env = env;
|
|
306
|
+
this.fallbackReason = fallbackReason;
|
|
307
|
+
this.capabilities = Object.freeze({
|
|
308
|
+
displayServer: 'win32',
|
|
309
|
+
screenshot: true,
|
|
310
|
+
mouse: true,
|
|
311
|
+
keyboard: true,
|
|
312
|
+
cursorPosition: true,
|
|
313
|
+
clipboard: true,
|
|
314
|
+
supportedActions: Object.freeze([
|
|
315
|
+
'screenshot',
|
|
316
|
+
'cursor_position',
|
|
317
|
+
'mouse_move',
|
|
318
|
+
'mouse_click',
|
|
319
|
+
'mouse_drag',
|
|
320
|
+
'scroll',
|
|
321
|
+
'type_text',
|
|
322
|
+
'key',
|
|
323
|
+
]),
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
static async create(options = {}) {
|
|
327
|
+
const env = options.env ?? process.env;
|
|
328
|
+
const platform = options.platform ?? process.platform;
|
|
329
|
+
const probes = options.wslProbes ?? realWslProbes;
|
|
330
|
+
const powershell = await findPowerShell(env, platform, probes);
|
|
331
|
+
if (!powershell) {
|
|
332
|
+
throw new AdapterUnavailableError(`Win32Adapter: neither PowerShell Core nor Windows PowerShell is available on PATH${options.fallbackReason ? `, and cua-driver was not usable: ${options.fallbackReason}` : ''}`, [...POWERSHELL_CANDIDATES]);
|
|
333
|
+
}
|
|
334
|
+
// Under WSL a systemd service has no working WSL_INTEROP; give it one.
|
|
335
|
+
const childEnv = isWsl(env, platform, probes) ? wslChildEnv(env, [], probes) : undefined;
|
|
336
|
+
return new Win32PowerShellAdapter(powershell, childEnv, options.fallbackReason);
|
|
337
|
+
}
|
|
338
|
+
async run(script) {
|
|
339
|
+
const result = await runCommandOrThrow(this.powershell, powerShellArguments(script), this.env ? { env: this.env } : {});
|
|
340
|
+
return result.stdout;
|
|
341
|
+
}
|
|
342
|
+
async getDisplayGeometry() {
|
|
343
|
+
const parsed = JSON.parse((await this.run(GEOMETRY_SCRIPT)).toString('utf8'));
|
|
344
|
+
return { width: parsed.width, height: parsed.height, scaleFactor: parsed.scaleFactor };
|
|
345
|
+
}
|
|
346
|
+
async execute(action) {
|
|
347
|
+
switch (action.type) {
|
|
348
|
+
case 'screenshot': {
|
|
349
|
+
const parsed = JSON.parse((await this.run(SCREENSHOT_SCRIPT)).toString('utf8'));
|
|
350
|
+
const data = Buffer.from(parsed.png, 'base64');
|
|
351
|
+
const dims = decodePngDims(data);
|
|
352
|
+
const display = {
|
|
353
|
+
id: 'primary',
|
|
354
|
+
x: parsed.x,
|
|
355
|
+
y: parsed.y,
|
|
356
|
+
width: parsed.width,
|
|
357
|
+
height: parsed.height,
|
|
358
|
+
scaleFactor: parsed.scaleFactor,
|
|
359
|
+
primary: true,
|
|
360
|
+
};
|
|
361
|
+
return {
|
|
362
|
+
type: 'screenshot',
|
|
363
|
+
result: { data, mimeType: 'image/png', width: dims.width, height: dims.height, display },
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
case 'cursor_position': {
|
|
367
|
+
const parsed = JSON.parse((await this.run(CURSOR_POSITION_SCRIPT)).toString('utf8'));
|
|
368
|
+
return { type: 'cursor_position', point: { x: parsed.x, y: parsed.y } };
|
|
369
|
+
}
|
|
370
|
+
case 'mouse_move':
|
|
371
|
+
await this.run(mouseMoveScript(action.to));
|
|
372
|
+
return { type: 'ok' };
|
|
373
|
+
case 'mouse_click':
|
|
374
|
+
await this.run(mouseClickScript(action.at, action.button));
|
|
375
|
+
return { type: 'ok' };
|
|
376
|
+
case 'mouse_drag':
|
|
377
|
+
await this.run(mouseDragScript(action.from, action.to, action.button));
|
|
378
|
+
return { type: 'ok' };
|
|
379
|
+
case 'scroll':
|
|
380
|
+
await this.run(scrollScript(action.at, action.direction, action.amount));
|
|
381
|
+
return { type: 'ok' };
|
|
382
|
+
case 'type_text':
|
|
383
|
+
await this.run(typeTextScript(action.text));
|
|
384
|
+
return { type: 'ok' };
|
|
385
|
+
case 'key':
|
|
386
|
+
await this.run(pressKeyScript(action.keys));
|
|
387
|
+
return { type: 'ok' };
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
function decodePngDims(buffer) {
|
|
392
|
+
if (buffer.length < 24) {
|
|
393
|
+
throw new Error('Win32Adapter: screenshot buffer too small to contain PNG header');
|
|
394
|
+
}
|
|
395
|
+
return {
|
|
396
|
+
width: buffer.readUInt32BE(16),
|
|
397
|
+
height: buffer.readUInt32BE(20),
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
/** For tests: the scripts as they are sent. */
|
|
401
|
+
export const _scripts = {
|
|
402
|
+
typeText: typeTextScript,
|
|
403
|
+
mouseDrag: mouseDragScript,
|
|
404
|
+
screenshot: SCREENSHOT_SCRIPT,
|
|
405
|
+
geometry: GEOMETRY_SCRIPT,
|
|
406
|
+
};
|
|
407
|
+
//# sourceMappingURL=win32-powershell.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"win32-powershell.js","sourceRoot":"","sources":["../../src/adapters/win32-powershell.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACnE,OAAO,EAAgB,uBAAuB,EAAE,MAAM,YAAY,CAAA;AAClE,OAAO,EAAkB,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAE/F;;;;;;GAMG;AAEH,8EAA8E;AAC9E,6EAA6E;AAC7E,8EAA8E;AAE9E,MAAM,iBAAiB,GAAqC;IAC3D,GAAG,EAAE,GAAG;I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a,CAAC,MAAc;IACpC,IAAI,MAAM,CAAC,MAAM,GAAG,EAAE,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,iEAAiE,CAAC,CAAA;IACnF,CAAC;IACD,OAAO;QACN,KAAK,EAAE,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC;QAC9B,MAAM,EAAE,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC;KAC/B,CAAA;AACF,CAAC;AAED,+CAA+C;AAC/C,MAAM,CAAC,MAAM,QAAQ,GAAG;IACvB,QAAQ,EAAE,cAAc;IACxB,SAAS,EAAE,eAAe;IAC1B,UAAU,EAAE,iBAAiB;IAC7B,QAAQ,EAAE,eAAe;CACzB,CAAA"}
|
package/dist/adapters/win32.d.ts
CHANGED
|
@@ -1,14 +1,42 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { CuaDriverAdapter } from './cua-driver/adapter.js';
|
|
2
|
+
import { resolveCuaDriver } from './cua-driver/provision.js';
|
|
3
3
|
import { type Adapter } from './types.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
import { type WslProbes } from './wsl.js';
|
|
5
|
+
/**
|
|
6
|
+
* Which Windows backend drives the desktop.
|
|
7
|
+
*
|
|
8
|
+
* - `auto` (the default): cua-driver — the pinned build, downloaded and
|
|
9
|
+
* checked on first use — and, when it cannot be had or does not answer,
|
|
10
|
+
* the per-action PowerShell path, with the reason on `fallbackReason`.
|
|
11
|
+
* - `cua-driver`: cua-driver or nothing; its failure is the adapter's.
|
|
12
|
+
* - `powershell`: never cua-driver.
|
|
13
|
+
*/
|
|
14
|
+
export type Win32Backend = 'auto' | 'cua-driver' | 'powershell';
|
|
15
|
+
export interface Win32AdapterOptions {
|
|
16
|
+
readonly backend?: Win32Backend;
|
|
17
|
+
/** An existing `cua-driver.exe` to run instead of the pinned build. */
|
|
18
|
+
readonly cuaDriverPath?: string;
|
|
19
|
+
/** Where the pinned build is kept. Default `<NAMZU_HOME>/computer-use/cua-driver/<version>`. */
|
|
20
|
+
readonly cacheDir?: string;
|
|
21
|
+
/** Download the pinned build when it is missing. Default true. */
|
|
22
|
+
readonly download?: boolean;
|
|
23
|
+
readonly env?: NodeJS.ProcessEnv;
|
|
24
|
+
readonly platform?: NodeJS.Platform;
|
|
25
|
+
/** For tests. */
|
|
26
|
+
readonly wslProbes?: WslProbes;
|
|
27
|
+
/** For tests. */
|
|
28
|
+
readonly resolve?: typeof resolveCuaDriver;
|
|
29
|
+
/** For tests. */
|
|
30
|
+
readonly createCuaDriverAdapter?: (options: ConstructorParameters<typeof CuaDriverAdapter>[0]) => Adapter;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The environment cua-driver runs with: the caller's minus anything named
|
|
34
|
+
* like a secret, plus {@link CUA_DRIVER_SETTINGS}; under WSL, with a working
|
|
35
|
+
* `WSL_INTEROP` and the settings forwarded through `WSLENV`.
|
|
36
|
+
*/
|
|
37
|
+
export declare function cuaDriverEnvironment(env: NodeJS.ProcessEnv, wsl: boolean, probes?: WslProbes): NodeJS.ProcessEnv;
|
|
38
|
+
export declare class Win32Adapter {
|
|
39
|
+
/** The Windows adapter for this host; see {@link Win32Backend}. */
|
|
40
|
+
static create(options?: Win32AdapterOptions): Promise<Adapter>;
|
|
12
41
|
}
|
|
13
|
-
export { runCommand as _runCommand };
|
|
14
42
|
//# sourceMappingURL=win32.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"win32.d.ts","sourceRoot":"","sources":["../../src/adapters/win32.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"win32.d.ts","sourceRoot":"","sources":["../../src/adapters/win32.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EAGN,gBAAgB,EAChB,MAAM,2BA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