@namzu/computer-use 1.4.3 → 2.0.2
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 +54 -1
- package/README.md +98 -8
- 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
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,58 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2.0.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 567ada8: Updated package examples and evaluation fixtures for the SDK's `ToolRegistry`
|
|
8
|
+
removal. Browser, computer-use and LSP documentation now show toolsets; the
|
|
9
|
+
evals use `toolsets` when they call the kernel. Provider changes are test
|
|
10
|
+
fixture migrations only, with no provider runtime API change. Consumers that
|
|
11
|
+
pass tools to the SDK should use `toolsets: readonly Toolset[]` and wrap their
|
|
12
|
+
definitions with `toolset(source, definitions)`.
|
|
13
|
+
|
|
14
|
+
## 2.0.1
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- 2d4ff9a: Earlier entries in this package's CHANGELOG no longer name one particular application built on namzu, or quote a path from outside this repository. This changes only the CHANGELOG.md that ships in the tarball; no code or types change, and there is nothing to do to upgrade.
|
|
19
|
+
|
|
20
|
+
## 2.0.0
|
|
21
|
+
|
|
22
|
+
### Major Changes
|
|
23
|
+
|
|
24
|
+
- 82769f1: On Windows and under WSL, `SubprocessComputerUseHost` now drives the desktop through cua-driver (MIT, github.com/trycua/cua) instead of starting `powershell.exe` for every action, and every adapter now takes and returns physical pixels. Both are changes a caller can see; read on before upgrading.
|
|
25
|
+
|
|
26
|
+
**What changes by default on Windows / WSL.** The first `initialize()` downloads cua-driver 0.28.2 for the machine's architecture (a 27–29 MB archive from the project's GitHub releases), checks the SHA-256 of the archive and of `cua-driver.exe` against values pinned in this package, and keeps only the executable in `<NAMZU_HOME>/computer-use/cua-driver/0.28.2/` (`~/.namzu` unless `NAMZU_HOME` is set). One `cua-driver.exe` process then runs until `host.dispose()`; call `dispose()` when you are done. It runs with its telemetry and release check off and without environment variables whose names look like secrets. If it cannot be downloaded, verified or started, the host falls back to PowerShell and says why in `host.fallbackReason`.
|
|
27
|
+
|
|
28
|
+
To keep the old behaviour — no download, no long-lived process — set `NAMZU_CUA_DRIVER=off` or pass `new SubprocessComputerUseHost({ windows: { backend: 'powershell' } })`. To use a cua-driver you installed yourself, set `NAMZU_CUA_DRIVER=<path to cua-driver.exe>` or `windows: { cuaDriverPath }`. `windows: { download: false }` uses only a cached or configured build.
|
|
29
|
+
|
|
30
|
+
**Physical pixels everywhere.** Points you pass to `execute()` and sizes you get back are pixels of the captured bitmap, as the SDK's host contract now states. This changes results only on scaled displays:
|
|
31
|
+
|
|
32
|
+
- macOS Retina: `getDisplayGeometry()` returns the capture's resolution (2880x1800, not 1440x900; 3360x2100 in a "Looks like 1680x1050" mode), `cursor_position` is in pixels, and click/move/drag points are pixels; the adapter divides by the capture's pixels per point for `cliclick` and System Events, once. Before, a click aimed at the middle of a Retina screenshot landed near the bottom-right corner. Screenshots show the main display only, the one the input tools address. If you converted screenshot pixels to points yourself, stop.
|
|
33
|
+
- Windows above 100 % scaling: both backends are DPI aware, so the capture is the whole display (it was the top-left part) and points are physical (they were DPI-virtualised).
|
|
34
|
+
- Every capture now carries `result.display` (`id`, origin, size, `scaleFactor`).
|
|
35
|
+
|
|
36
|
+
**Also new.** With the cua-driver backend, `capabilities.windows` is `true` and `host.listWindows()` / `host.focusWindow(id)` work (focus restores a minimised window and reports what is actually in front); `host.captureRegion()` exists and throws where the adapter has no region capture. `host.backend` names the backend in use. Measured on a 3440x1440 display: a click went from 0.68–0.83 s to 0.13 s, a screenshot from 0.40 s to 0.08–0.13 s.
|
|
37
|
+
|
|
38
|
+
**Smaller differences on the cua-driver backend.** `capabilities.clipboard` is `false` (no clipboard action was ever offered); `win`/`super` in a key chord press the Windows key (PowerShell's SendKeys pressed Ctrl); a single punctuation key such as `/` is typed as text so the keyboard layout cannot change it. Only the primary display is captured, as before. The PowerShell fallback now types text through Unicode key events instead of SendKeys, so `+ ^ % ~ ( ) { }` and non-Latin text arrive as written.
|
|
39
|
+
|
|
40
|
+
### Minor Changes
|
|
41
|
+
|
|
42
|
+
- 82769f1: `computer_use` can read a window's controls and act on them by reference, on a host that declares `uiTree` — which the Windows backend of `@namzu/computer-use` now does.
|
|
43
|
+
|
|
44
|
+
**What changes for a caller of the tool**
|
|
45
|
+
|
|
46
|
+
- Two new actions when the host declares `uiTree` and implements `uiSnapshot` and `uiAct`: `ui_snapshot { window_id? }` returns the window's accessibility tree as text, each control that can be acted on with a ref such as `e12`; `ui_act { ref, action, value? }` performs `invoke`, `set_value`, `toggle`, `select`, `expand`, `collapse`, `focus` or `scroll_into_view` on it and returns a screenshot afterwards. `ui_act` may be in a batch; `ui_snapshot` may not. Refs count up across snapshots and only the latest snapshot's are accepted, so a stale ref is refused rather than acting on another control. `ActionInput` gains both, so code that switches exhaustively over `input.type` needs two more cases — that is why this is a major release for `@namzu/sdk`.
|
|
47
|
+
- `ui_snapshot` is read-only; `ui_act` is destructive.
|
|
48
|
+
- `list_windows` now returns its window lines inside an untrusted-content frame (`<namzu-untrusted kind="desktop-windows">`), since titles are whatever each application shows. The lines themselves are unchanged; code that parsed the whole output text needs to skip the frame's three header lines.
|
|
49
|
+
- `createComputerUseTool` returns a `ComputerUseTool`, a `ToolDefinition<ActionInput>` with `describeUiRef(ref)` (experimental), which names the control a ref points at for a review screen.
|
|
50
|
+
- `UiSnapshot` gains optional `title` and `app`; `UiElement.ref` is empty for an element nothing can be done with. Both types stay experimental.
|
|
51
|
+
|
|
52
|
+
**`@namzu/computer-use`**
|
|
53
|
+
|
|
54
|
+
On Windows and WSL with the cua-driver backend, `capabilities.uiTree` is `true` and `SubprocessComputerUseHost` offers `uiSnapshot(windowId?)` and `uiAct(ref, action, value?)`, read from cua-driver's UI Automation walk. A control is invoked in the background, without moving the pointer or bringing its window to the front; a field without a settable value is typed into when it is empty. An action whose driver died mid-request comes back as not done with an unknown outcome, never retried. The PowerShell fallback and the other platforms do not declare `uiTree`, so nothing changes there.
|
|
55
|
+
|
|
3
56
|
## 1.4.3
|
|
4
57
|
|
|
5
58
|
### Patch Changes
|
|
@@ -163,7 +216,7 @@
|
|
|
163
216
|
What a consumer sees change:
|
|
164
217
|
|
|
165
218
|
- `@namzu/sandbox` raised `Sandbox backend 'x' is not implemented yet. Track
|
|
166
|
-
progress in
|
|
219
|
+
progress in <a local notes directory>/...` — a runtime error
|
|
167
220
|
instructing the reader to open a path that is not in the package, not in the
|
|
168
221
|
repository, and not on the internet. It now names what does ship instead.
|
|
169
222
|
- `@namzu/computer-use`'s README linked to an adapter-pattern document under a
|
package/README.md
CHANGED
|
@@ -34,7 +34,8 @@ Adapters publish an exact `supportedActions` subset. Optional `mouseClickButtons
|
|
|
34
34
|
and `mouseDragButtons` distinguish gesture support: on macOS scrolling is
|
|
35
35
|
unavailable, move/drag require cliclick, and drag supports only the left button.
|
|
36
36
|
The SDK tool filters its advertised actions and rejects unsupported gestures
|
|
37
|
-
before desktop execution. See [
|
|
37
|
+
before desktop execution. See [the computer_use tool](../../docs/sdk/computer-actions.md)
|
|
38
|
+
and [the host contract](../../docs/sdk/computer-use-host.md).
|
|
38
39
|
|
|
39
40
|
## Install
|
|
40
41
|
|
|
@@ -51,7 +52,7 @@ import {
|
|
|
51
52
|
SubprocessComputerUseHost,
|
|
52
53
|
type SubprocessComputerUseHostOptions,
|
|
53
54
|
} from '@namzu/computer-use'
|
|
54
|
-
import { createComputerUseTool,
|
|
55
|
+
import { createComputerUseTool, toolset } from '@namzu/sdk'
|
|
55
56
|
|
|
56
57
|
const options: SubprocessComputerUseHostOptions = {
|
|
57
58
|
env: process.env,
|
|
@@ -70,8 +71,7 @@ console.log(host.capabilities)
|
|
|
70
71
|
// clipboard: true,
|
|
71
72
|
// }
|
|
72
73
|
|
|
73
|
-
const
|
|
74
|
-
registry.register(createComputerUseTool(host))
|
|
74
|
+
const tools = toolset('computer-use', [createComputerUseTool(host)])
|
|
75
75
|
```
|
|
76
76
|
|
|
77
77
|
If a click, drag, scroll, text entry or key subprocess starts but does not
|
|
@@ -80,10 +80,100 @@ report a clean completion, the host throws
|
|
|
80
80
|
SDK returns that state to the model with `retrySafety: 'unsafe'` instead of
|
|
81
81
|
inviting an automatic replay.
|
|
82
82
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
`
|
|
86
|
-
|
|
83
|
+
Every coordinate and size crossing the host is in **physical pixels**: the
|
|
84
|
+
pixels of the captured bitmap, never points or DPI-scaled units. A capture
|
|
85
|
+
carries `display` (origin, size, `scaleFactor`) and action points are
|
|
86
|
+
relative to that display. On a Retina Mac the adapter converts to points for
|
|
87
|
+
`cliclick` itself, so a click at the pixel you saw lands there; on Windows
|
|
88
|
+
every backend is DPI aware.
|
|
89
|
+
|
|
90
|
+
`host.dispose()` stops whatever the adapter keeps running. Call it when the
|
|
91
|
+
session ends.
|
|
92
|
+
|
|
93
|
+
## Windows and WSL
|
|
94
|
+
|
|
95
|
+
When Namzu runs inside WSL, the host selects the paired Windows desktop. This
|
|
96
|
+
takes precedence over WSLg's `DISPLAY`/`WAYLAND_DISPLAY`, which describe Linux
|
|
97
|
+
GUI applications rather than the Windows desktop containing the terminal.
|
|
98
|
+
|
|
99
|
+
The desktop is driven by [cua-driver](https://github.com/trycua/cua) (MIT),
|
|
100
|
+
one `cua-driver.exe mcp` process for the host's lifetime, spoken to over its
|
|
101
|
+
standard streams:
|
|
102
|
+
|
|
103
|
+
- **Pinned and checked.** The first `initialize()` downloads cua-driver
|
|
104
|
+
0.28.2 for this architecture (x64 or arm64, a 27–29 MB archive from the
|
|
105
|
+
project's GitHub releases), checks the SHA-256 of the archive and of the
|
|
106
|
+
executable in it against values in this package, and keeps
|
|
107
|
+
`cua-driver.exe` in `<NAMZU_HOME>/computer-use/cua-driver/0.28.2/`
|
|
108
|
+
(`~/.namzu` by default). Nothing else in the archive is written. Later
|
|
109
|
+
sessions start the cached copy after checking its hash again.
|
|
110
|
+
- **Quiet.** It runs with its telemetry and its release check switched off
|
|
111
|
+
(`CUA_DRIVER_RS_TELEMETRY_ENABLED=0`, `CUA_DRIVER_RS_UPDATE_CHECK=0`,
|
|
112
|
+
forwarded through `WSLENV`), without any environment variable whose name
|
|
113
|
+
looks like a secret, and with its animated agent cursor off. Measured: a
|
|
114
|
+
whole session left nothing in the Windows user profile.
|
|
115
|
+
- **Windows.** `capabilities.windows` is `true`: `listWindows()` and
|
|
116
|
+
`focusWindow(id)` (which restores a minimized window, gets past the
|
|
117
|
+
foreground lock and reports what is actually in front afterwards).
|
|
118
|
+
- **Controls (experimental).** `capabilities.uiTree` is `true`:
|
|
119
|
+
`uiSnapshot(windowId?)` reads a window's UI Automation tree (the window in
|
|
120
|
+
front without an id) and `uiAct(ref, action, value?)` acts on a control of
|
|
121
|
+
the latest snapshot — `invoke`, `toggle`, `select`, `expand`, `collapse`
|
|
122
|
+
through UI Automation in the background, `set_value` through the control's
|
|
123
|
+
value, or by typing into an empty field that has none. The SDK tool offers
|
|
124
|
+
these as `ui_snapshot` and `ui_act`. Pressing six Calculator buttons this
|
|
125
|
+
way took about 90 ms, without bringing the window to the front.
|
|
126
|
+
- **Fallback.** When cua-driver cannot be downloaded, verified or started,
|
|
127
|
+
or does not reach the desktop, the host uses PowerShell instead — one
|
|
128
|
+
`powershell.exe` per action, DPI aware, Unicode text, no window list.
|
|
129
|
+
`host.backend` says which is in use (`cua-driver 0.28.2`, `powershell`),
|
|
130
|
+
`host.fallbackReason` why cua-driver is not.
|
|
131
|
+
|
|
132
|
+
`NAMZU_CUA_DRIVER=off` keeps cua-driver out (no download); a path in it runs
|
|
133
|
+
that `cua-driver.exe` instead of the pinned build. The same choices in code:
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
import { SubprocessComputerUseHost } from '@namzu/computer-use'
|
|
137
|
+
|
|
138
|
+
const host = new SubprocessComputerUseHost({
|
|
139
|
+
windows: {
|
|
140
|
+
backend: 'auto', // or 'cua-driver' (no fallback) or 'powershell'
|
|
141
|
+
download: true, // false: use a cached or configured build only
|
|
142
|
+
},
|
|
143
|
+
})
|
|
144
|
+
await host.initialize()
|
|
145
|
+
console.log(host.backend, host.fallbackReason)
|
|
146
|
+
if (host.capabilities.windows) {
|
|
147
|
+
const windows = await host.listWindows()
|
|
148
|
+
const notepad = windows.find((window) => window.app === 'notepad')
|
|
149
|
+
if (notepad) await host.focusWindow(notepad.id)
|
|
150
|
+
}
|
|
151
|
+
await host.dispose()
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Measured on Windows 10 22H2 from WSL2, one 3440x1440 display at 100 %:
|
|
155
|
+
|
|
156
|
+
| Call | PowerShell per action (before) | cua-driver |
|
|
157
|
+
| --- | --- | --- |
|
|
158
|
+
| `initialize()` | 0.3 s | 0.5–0.7 s (2.2 s the first time, with the download) |
|
|
159
|
+
| screenshot (3440x1440 PNG) | 0.40–0.42 s | 0.08–0.13 s |
|
|
160
|
+
| cursor position | 0.31 s | 1–6 ms |
|
|
161
|
+
| move | 0.54–0.60 s | 1–5 ms |
|
|
162
|
+
| click | 0.68–0.83 s | 0.13–0.14 s |
|
|
163
|
+
| key | not measured | 0.04–0.05 s |
|
|
164
|
+
| type 21 characters | not measured | 0.09 s |
|
|
165
|
+
| focus a window | not offered | 4–22 ms |
|
|
166
|
+
| list windows | not offered | 1.2–1.9 s |
|
|
167
|
+
|
|
168
|
+
What cua-driver does not do, and so neither does this host on Windows: it
|
|
169
|
+
captures the primary display only; it has no region capture (the SDK crops a
|
|
170
|
+
full capture instead); its window list includes windows Windows keeps
|
|
171
|
+
cloaked (a suspended Settings app, the text-input host), and it does not say
|
|
172
|
+
which window has focus — `focused` is the front-most window that is not
|
|
173
|
+
minimized. A single punctuation key (`/`, `+`) is typed as text, because
|
|
174
|
+
cua-driver resolves it to a key without its shift state and on a Turkish
|
|
175
|
+
layout `/` came out as `7`; a chord such as `ctrl+/` still goes through
|
|
176
|
+
cua-driver's key mapping.
|
|
87
177
|
|
|
88
178
|
## Documentation
|
|
89
179
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { ComputerUseAction, ComputerUseCapabilities, ComputerUseHost, ComputerUseResult, DisplayGeometry } from '@namzu/sdk';
|
|
1
|
+
import type { ComputerUseAction, ComputerUseCapabilities, ComputerUseHost, ComputerUseResult, DisplayGeometry, FocusWindowResult, Rect, ScreenshotResult, UiActResult, UiElementAction, UiSnapshot, WindowInfo } from '@namzu/sdk';
|
|
2
2
|
import { type Adapter } from './adapters/types.js';
|
|
3
|
+
import type { Win32AdapterOptions } from './adapters/win32.js';
|
|
3
4
|
export interface SubprocessComputerUseHostOptions {
|
|
4
5
|
readonly env?: NodeJS.ProcessEnv;
|
|
5
6
|
readonly platform?: NodeJS.Platform;
|
|
@@ -9,27 +10,66 @@ export interface SubprocessComputerUseHostOptions {
|
|
|
9
10
|
* correct adapter automatically.
|
|
10
11
|
*/
|
|
11
12
|
readonly adapter?: Adapter;
|
|
13
|
+
/**
|
|
14
|
+
* The Windows backend (WSL included): cua-driver, pinned and downloaded on
|
|
15
|
+
* first use, with the PowerShell path as its fallback. See the README.
|
|
16
|
+
*/
|
|
17
|
+
readonly windows?: SubprocessComputerUseHostWindowsOptions;
|
|
12
18
|
}
|
|
19
|
+
export type SubprocessComputerUseHostWindowsOptions = Pick<Win32AdapterOptions, 'backend' | 'cuaDriverPath' | 'cacheDir' | 'download'>;
|
|
13
20
|
/**
|
|
14
21
|
* Subprocess-backed ComputerUseHost. Delegates platform-specific work to
|
|
15
22
|
* adapters that spawn system CLIs (`screencapture`, `osascript`, `xdotool`,
|
|
16
|
-
* `maim`, `grim`, PowerShell)
|
|
17
|
-
*
|
|
18
|
-
* Node/libuv — each subprocess owns
|
|
23
|
+
* `maim`, `grim`, PowerShell) or, on Windows, keep one cua-driver process.
|
|
24
|
+
* The child-process model side-steps the macOS CFRunLoop pump problem that
|
|
25
|
+
* blocks in-process native addons under Node/libuv — each subprocess owns
|
|
26
|
+
* its own main thread.
|
|
19
27
|
*
|
|
20
28
|
* Lifecycle: `initialize()` probes the environment and selects the adapter.
|
|
21
29
|
* Until then, `capabilities.displayServer` reflects detection but every
|
|
22
|
-
* feature flag is `false`, and `execute` throws.
|
|
30
|
+
* feature flag is `false`, and `execute` throws. `dispose()` stops what the
|
|
31
|
+
* adapter keeps running.
|
|
23
32
|
*/
|
|
24
33
|
export declare class SubprocessComputerUseHost implements ComputerUseHost {
|
|
34
|
+
private readonly options;
|
|
25
35
|
readonly id = "subprocess-computer-use-host";
|
|
26
36
|
private _capabilities;
|
|
27
37
|
private adapter;
|
|
28
38
|
constructor(options?: SubprocessComputerUseHostOptions);
|
|
29
39
|
get capabilities(): ComputerUseCapabilities;
|
|
40
|
+
/**
|
|
41
|
+
* What drives the desktop once initialised — `cua-driver 0.28.2`,
|
|
42
|
+
* `powershell`, … — for logs and diagnosis. Undefined before
|
|
43
|
+
* `initialize()` and for adapters that do not say.
|
|
44
|
+
*/
|
|
45
|
+
get backend(): string | undefined;
|
|
46
|
+
/** Why the preferred backend is not the one in use, when the adapter fell back. */
|
|
47
|
+
get fallbackReason(): string | undefined;
|
|
30
48
|
initialize(): Promise<void>;
|
|
31
49
|
getDisplayGeometry(): Promise<DisplayGeometry>;
|
|
32
50
|
execute(action: ComputerUseAction): Promise<ComputerUseResult>;
|
|
51
|
+
/** Offered to the model only when `capabilities.windows` is true. */
|
|
52
|
+
listWindows(): Promise<readonly WindowInfo[]>;
|
|
53
|
+
/** Offered to the model only when `capabilities.windows` is true. */
|
|
54
|
+
focusWindow(id: string): Promise<FocusWindowResult>;
|
|
55
|
+
/** Offered to the model only when `capabilities.regionCapture` is true. */
|
|
56
|
+
captureRegion(rect: Rect): Promise<ScreenshotResult>;
|
|
57
|
+
/**
|
|
58
|
+
* A window's controls. Offered to the model only when
|
|
59
|
+
* `capabilities.uiTree` is true.
|
|
60
|
+
*
|
|
61
|
+
* @experimental Follows the SDK's UI-tree surface.
|
|
62
|
+
*/
|
|
63
|
+
uiSnapshot(windowId?: string): Promise<UiSnapshot>;
|
|
64
|
+
/**
|
|
65
|
+
* Act on a control of the latest {@link uiSnapshot}. A request lost after
|
|
66
|
+
* it was sent (the driver died or stopped answering) may have acted, so
|
|
67
|
+
* it is reported as not done with an unknown outcome, never retried.
|
|
68
|
+
*
|
|
69
|
+
* @experimental Follows the SDK's UI-tree surface.
|
|
70
|
+
*/
|
|
71
|
+
uiAct(ref: string, action: UiElementAction, value?: string): Promise<UiActResult>;
|
|
72
|
+
/** Stops whatever the adapter keeps running (the Windows cua-driver process). */
|
|
33
73
|
dispose(): Promise<void>;
|
|
34
74
|
private requireAdapter;
|
|
35
75
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SubprocessComputerUseHost.d.ts","sourceRoot":"","sources":["../src/SubprocessComputerUseHost.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,iBAAiB,EACjB,uBAAuB,EACvB,eAAe,EACf,iBAAiB,EACjB,eAAe,EACf,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,KAAK,OAAO,EAA2B,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"SubprocessComputerUseHost.d.ts","sourceRoot":"","sources":["../src/SubprocessComputerUseHost.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,iBAAiB,EACjB,uBAAuB,EACvB,eAAe,EACf,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,IAAI,EACJ,gBAAgB,EAChB,WAAW,EACX,eAAe,EACf,UAAU,EACV,UAAU,EACV,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,KAAK,OAAO,EAA2B,MAAM,qBAAqB,CAAA;AAC3E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AAsB9D,MAAM,WAAW,gCAAgC;IAChD,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAA;IAChC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAA;IACnC;;;;OAIG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAA;IAC1B;;;OAGG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,uCAAuC,CAAA;CAC1D;AAED,MAAM,MAAM,uCAAuC,GAAG,IAAI,CACzD,mBAAmB,EACnB,SAAS,G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/**
|
|
21
21
|
* Subprocess-backed ComputerUseHost. Delegates platform-specific work to
|
|
22
22
|
* adapters that spawn system CLIs (`screencapture`, `osascript`, `xdotool`,
|
|
23
|
-
* `maim`, `grim`, PowerShell)
|
|
24
|
-
*
|
|
25
|
-
* Node/libuv — each subprocess owns
|
|
23
|
+
* `maim`, `grim`, PowerShell) or, on Windows, keep one cua-driver process.
|
|
24
|
+
* The child-process model side-steps the macOS CFRunLoop pump problem that
|
|
25
|
+
* blocks in-process native addons under Node/libuv — each subprocess owns
|
|
26
|
+
* its own main thread.
|
|
26
27
|
*
|
|
27
28
|
* Lifecycle: `initialize()` probes the environment and selects the adapter.
|
|
28
29
|
* Until then, `capabilities.displayServer` reflects detection but every
|
|
29
|
-
* feature flag is `false`, and `execute` throws.
|
|
30
|
+
* feature flag is `false`, and `execute` throws. `dispose()` stops what the
|
|
31
|
+
* adapter keeps running.
|
|
30
32
|
*/
|
|
31
33
|
export class SubprocessComputerUseHost {
|
|
34
|
+
options;
|
|
32
35
|
id = 'subprocess-computer-use-host';
|
|
33
36
|
_capabilities;
|
|
34
37
|
adapter = null;
|
|
35
38
|
constructor(options = {}) {
|
|
39
|
+
this.options = options;
|
|
36
40
|
const displayServer = detectDisplayServer(options.env, options.platform);
|
|
37
41
|
this._capabilities = Object.freeze({
|
|
38
42
|
...UNINITIALISED_CAPABILITIES,
|
|
@@ -46,11 +50,23 @@ export class SubprocessComputerUseHost {
|
|
|
46
50
|
get capabilities() {
|
|
47
51
|
return this._capabilities;
|
|
48
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* What drives the desktop once initialised — `cua-driver 0.28.2`,
|
|
55
|
+
* `powershell`, … — for logs and diagnosis. Undefined before
|
|
56
|
+
* `initialize()` and for adapters that do not say.
|
|
57
|
+
*/
|
|
58
|
+
get backend() {
|
|
59
|
+
return this.adapter?.backend;
|
|
60
|
+
}
|
|
61
|
+
/** Why the preferred backend is not the one in use, when the adapter fell back. */
|
|
62
|
+
get fallbackReason() {
|
|
63
|
+
return this.adapter?.fallbackReason;
|
|
64
|
+
}
|
|
49
65
|
async initialize() {
|
|
50
66
|
if (this.adapter)
|
|
51
67
|
return;
|
|
52
68
|
const displayServer = this._capabilities.displayServer;
|
|
53
|
-
const adapter = await loadAdapter(displayServer);
|
|
69
|
+
const adapter = await loadAdapter(displayServer, this.options);
|
|
54
70
|
// Loading an adapter proves its tools exist on PATH, not that a desktop
|
|
55
71
|
// answers. A WSL process finds PowerShell and still may have no
|
|
56
72
|
// interactive Windows session to capture; an ssh session finds xdotool
|
|
@@ -62,8 +78,12 @@ export class SubprocessComputerUseHost {
|
|
|
62
78
|
await adapter.getDisplayGeometry();
|
|
63
79
|
}
|
|
64
80
|
catch (error) {
|
|
81
|
+
await adapter.dispose?.().catch(() => undefined);
|
|
65
82
|
const reason = error instanceof Error ? error.message : String(error);
|
|
66
|
-
|
|
83
|
+
const fallback = adapter.fallbackReason
|
|
84
|
+
? ` (cua-driver was not used: ${adapter.fallbackReason})`
|
|
85
|
+
: '';
|
|
86
|
+
throw new AdapterUnavailableError(`SubprocessComputerUseHost: the ${displayServer} adapter loaded but the desktop did not answer: ${reason}${fallback}`);
|
|
67
87
|
}
|
|
68
88
|
this.adapter = adapter;
|
|
69
89
|
this._capabilities = adapter.capabilities;
|
|
@@ -90,8 +110,67 @@ export class SubprocessComputerUseHost {
|
|
|
90
110
|
throw error;
|
|
91
111
|
}
|
|
92
112
|
}
|
|
113
|
+
/** Offered to the model only when `capabilities.windows` is true. */
|
|
114
|
+
async listWindows() {
|
|
115
|
+
const adapter = this.requireAdapter();
|
|
116
|
+
if (!adapter.listWindows)
|
|
117
|
+
throw unsupported('listWindows', this._capabilities.displayServer);
|
|
118
|
+
return adapter.listWindows();
|
|
119
|
+
}
|
|
120
|
+
/** Offered to the model only when `capabilities.windows` is true. */
|
|
121
|
+
async focusWindow(id) {
|
|
122
|
+
const adapter = this.requireAdapter();
|
|
123
|
+
if (!adapter.focusWindow)
|
|
124
|
+
throw unsupported('focusWindow', this._capabilities.displayServer);
|
|
125
|
+
return adapter.focusWindow(id);
|
|
126
|
+
}
|
|
127
|
+
/** Offered to the model only when `capabilities.regionCapture` is true. */
|
|
128
|
+
async captureRegion(rect) {
|
|
129
|
+
const adapter = this.requireAdapter();
|
|
130
|
+
if (!adapter.captureRegion)
|
|
131
|
+
throw unsupported('captureRegion', this._capabilities.displayServer);
|
|
132
|
+
return adapter.captureRegion(rect);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* A window's controls. Offered to the model only when
|
|
136
|
+
* `capabilities.uiTree` is true.
|
|
137
|
+
*
|
|
138
|
+
* @experimental Follows the SDK's UI-tree surface.
|
|
139
|
+
*/
|
|
140
|
+
async uiSnapshot(windowId) {
|
|
141
|
+
const adapter = this.requireAdapter();
|
|
142
|
+
if (!adapter.uiSnapshot)
|
|
143
|
+
throw unsupported('uiSnapshot', this._capabilities.displayServer);
|
|
144
|
+
return adapter.uiSnapshot(windowId);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Act on a control of the latest {@link uiSnapshot}. A request lost after
|
|
148
|
+
* it was sent (the driver died or stopped answering) may have acted, so
|
|
149
|
+
* it is reported as not done with an unknown outcome, never retried.
|
|
150
|
+
*
|
|
151
|
+
* @experimental Follows the SDK's UI-tree surface.
|
|
152
|
+
*/
|
|
153
|
+
async uiAct(ref, action, value) {
|
|
154
|
+
const adapter = this.requireAdapter();
|
|
155
|
+
if (!adapter.uiAct)
|
|
156
|
+
throw unsupported('uiAct', this._capabilities.displayServer);
|
|
157
|
+
try {
|
|
158
|
+
return await adapter.uiAct(ref, action, value);
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
if (error instanceof SpawnError)
|
|
162
|
+
return {
|
|
163
|
+
ok: false,
|
|
164
|
+
detail: `the desktop driver stopped before it answered, so ${action} may or may not have happened; look at the screen (ui_snapshot or screenshot) before trying again. ${error.message}`,
|
|
165
|
+
};
|
|
166
|
+
throw error;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/** Stops whatever the adapter keeps running (the Windows cua-driver process). */
|
|
93
170
|
async dispose() {
|
|
171
|
+
const adapter = this.adapter;
|
|
94
172
|
this.adapter = null;
|
|
173
|
+
await adapter?.dispose?.();
|
|
95
174
|
}
|
|
96
175
|
requireAdapter() {
|
|
97
176
|
if (!this.adapter) {
|
|
@@ -100,7 +179,10 @@ export class SubprocessComputerUseHost {
|
|
|
100
179
|
return this.adapter;
|
|
101
180
|
}
|
|
102
181
|
}
|
|
103
|
-
|
|
182
|
+
function unsupported(method, displayServer) {
|
|
183
|
+
return new Error(`SubprocessComputerUseHost: ${method} is not supported by the ${displayServer} adapter in use.`);
|
|
184
|
+
}
|
|
185
|
+
async function loadAdapter(displayServer, options) {
|
|
104
186
|
switch (displayServer) {
|
|
105
187
|
case 'darwin': {
|
|
106
188
|
const { DarwinAdapter } = await import('./adapters/darwin.js');
|
|
@@ -116,7 +198,11 @@ async function loadAdapter(displayServer) {
|
|
|
116
198
|
}
|
|
117
199
|
case 'win32': {
|
|
118
200
|
const { Win32Adapter } = await import('./adapters/win32.js');
|
|
119
|
-
return Win32Adapter.create(
|
|
201
|
+
return Win32Adapter.create({
|
|
202
|
+
...options.windows,
|
|
203
|
+
...(options.env !== undefined ? { env: options.env } : {}),
|
|
204
|
+
...(options.platform !== undefined ? { platform: options.platform } : {}),
|
|
205
|
+
});
|
|
120
206
|
}
|
|
121
207
|
case 'unknown':
|
|
122
208
|
throw new Error(`SubprocessComputerUseHost: no adapter available for displayServer="${displayServer}" yet`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SubprocessComputerUseHost.js","sourceRoot":"","sources":["../src/SubprocessComputerUseHost.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SubprocessComputerUseHost.js","sourceRoot":"","sources":["../src/SubprocessComputerUseHost.ts"],"names":[],"mappings":"AAcA,OAAO,EAAgB,uBAAuB,EAAE,MAAM,qBA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,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aACzE,CAAC,CAAA;QACH,CAAC;QACD,KAAK,SAAS;YACb,MAAM,IAAI,KAAK,CACd,sEAAsE,aAAa,OAAO,CAC1F,CAAA;IACH,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { ComputerUseAction, ComputerUseCapabilities, ComputerUseResult, DisplayGeometry, FocusWindowResult, UiActResult, UiElementAction, UiSnapshot, WindowInfo } from '@namzu/sdk';
|
|
2
|
+
import type { Adapter } from '../types.js';
|
|
3
|
+
import { type McpStdioClientOptions, type McpToolResult } from './client.js';
|
|
4
|
+
/**
|
|
5
|
+
* The Windows desktop through cua-driver (github.com/trycua/cua, MIT): one
|
|
6
|
+
* `cua-driver.exe mcp` process for the adapter's lifetime, spoken to as an
|
|
7
|
+
* MCP server over its standard streams.
|
|
8
|
+
*
|
|
9
|
+
* Every input goes to cua-driver's `desktop` scope: real `SendInput` at
|
|
10
|
+
* screen coordinates, which is this package's contract. Its default
|
|
11
|
+
* `window` scope posts messages to a process in the background instead, a
|
|
12
|
+
* different model this adapter does not expose.
|
|
13
|
+
*
|
|
14
|
+
* What the adapter adds on top:
|
|
15
|
+
* - the animated agent cursor is switched off for its session: with it, a
|
|
16
|
+
* click took 0.9–3.8 s (the cursor glides to the target) instead of about
|
|
17
|
+
* 0.12 s, and a full-screen overlay window joined the window list;
|
|
18
|
+
* - a single printable key is typed as text (see `./keys.ts`);
|
|
19
|
+
* - a pointer action whose only failure is cua-driver's after-the-fact
|
|
20
|
+
* foreground check is reported as done (see {@link isDeliveredPointerAction});
|
|
21
|
+
* - the window list drops cua-driver's own overlay, the shell's desktop and
|
|
22
|
+
* 1-pixel windows, and orders it front to back;
|
|
23
|
+
* - a window's UI Automation tree (`get_window_state`) becomes a `UiSnapshot`
|
|
24
|
+
* whose refs are cua-driver's element tokens, and `uiAct` drives a control
|
|
25
|
+
* by token: UIA Invoke for a button, ValuePattern for a field, falling back
|
|
26
|
+
* to typing into a field that is empty and has no settable value (classic
|
|
27
|
+
* Notepad's editor is one).
|
|
28
|
+
*/
|
|
29
|
+
export interface CuaDriverAdapterOptions {
|
|
30
|
+
/** `cua-driver.exe`, as this process starts it (a Linux path under WSL). */
|
|
31
|
+
readonly executable: string;
|
|
32
|
+
/** The environment for it; see `cuaDriverEnvironment` in `../win32.ts`. */
|
|
33
|
+
readonly env: NodeJS.ProcessEnv;
|
|
34
|
+
readonly cwd?: string;
|
|
35
|
+
/** For the backend label; the pinned version when it is the pinned build. */
|
|
36
|
+
readonly version?: string;
|
|
37
|
+
/** For tests. */
|
|
38
|
+
readonly spawnProcess?: McpStdioClientOptions['spawnProcess'];
|
|
39
|
+
readonly requestTimeoutMs?: number;
|
|
40
|
+
readonly startTimeoutMs?: number;
|
|
41
|
+
}
|
|
42
|
+
export declare class CuaDriverAdapter implements Adapter {
|
|
43
|
+
readonly capabilities: ComputerUseCapabilities;
|
|
44
|
+
readonly backend: string;
|
|
45
|
+
private readonly client;
|
|
46
|
+
/** Window id → owning pid, from the latest list; `bring_to_front` needs both. */
|
|
47
|
+
private readonly windowPids;
|
|
48
|
+
/** The refs of the latest UI snapshot: element token → its window's pid and what it held. */
|
|
49
|
+
private uiRefs;
|
|
50
|
+
constructor(options: CuaDriverAdapterOptions);
|
|
51
|
+
/** How many driver processes this adapter has started (a restart after a crash counts). */
|
|
52
|
+
get processStarts(): number;
|
|
53
|
+
getDisplayGeometry(): Promise<DisplayGeometry>;
|
|
54
|
+
execute(action: ComputerUseAction): Promise<ComputerUseResult>;
|
|
55
|
+
listWindows(): Promise<readonly WindowInfo[]>;
|
|
56
|
+
focusWindow(id: string): Promise<FocusWindowResult>;
|
|
57
|
+
/**
|
|
58
|
+
* One window's controls. Without an id, the window in front — which,
|
|
59
|
+
* for an agent run from a terminal, is usually that terminal.
|
|
60
|
+
*/
|
|
61
|
+
uiSnapshot(windowId?: string): Promise<UiSnapshot>;
|
|
62
|
+
uiAct(ref: string, action: UiElementAction, value?: string): Promise<UiActResult>;
|
|
63
|
+
dispose(): Promise<void>;
|
|
64
|
+
/** A window id (or the window in front) → its handle and owning process. */
|
|
65
|
+
private resolveWindow;
|
|
66
|
+
private pointer;
|
|
67
|
+
private capture;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* cua-driver activates the window under a desktop click, clicks, and then
|
|
71
|
+
* checks that the window — or another of its process — is still in front. A
|
|
72
|
+
* click that closes its own window (a dialog's "Don't Save", a close button)
|
|
73
|
+
* or starts another program leaves someone else in front, and the check
|
|
74
|
+
* fails although the click happened: "…was not foreground after the click".
|
|
75
|
+
* Reporting that as a failure would invite the model to click again, so it
|
|
76
|
+
* counts as done. The refusals that come before any input say "no input was
|
|
77
|
+
* sent" / "no mouse input was sent" and stay failures.
|
|
78
|
+
*/
|
|
79
|
+
export declare function isDeliveredPointerAction(error: unknown): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* cua-driver's action result → the host's. `confirmed`, `partial` and
|
|
82
|
+
* `unverifiable` count as done: a background UIA Invoke is `unverifiable` by
|
|
83
|
+
* design (the control does not report back), and the screenshot the tool
|
|
84
|
+
* takes afterwards is where the model sees the effect.
|
|
85
|
+
*/
|
|
86
|
+
export declare function actResult(result: McpToolResult): UiActResult;
|
|
87
|
+
/** `0x…` hex, the form `bring_to_front` reports and `WindowInfo.id` carries. */
|
|
88
|
+
export declare function windowIdOf(hwnd: number): string;
|
|
89
|
+
export declare function parseWindowId(value: unknown): number | undefined;
|
|
90
|
+
/**
|
|
91
|
+
* cua-driver's `list_windows` records → the host's `WindowInfo`, front to back.
|
|
92
|
+
*
|
|
93
|
+
* Dropped: untitled windows, cua-driver's own (its cursor overlay covers the
|
|
94
|
+
* whole screen), the shell's `Program Manager` desktop, and windows a pixel
|
|
95
|
+
* wide or tall. `focused` is the front-most window that is not minimized —
|
|
96
|
+
* cua-driver does not report the foreground window itself, and the
|
|
97
|
+
* foreground window is the front of the non-topmost z-order.
|
|
98
|
+
*/
|
|
99
|
+
export declare function toWindowInfos(raw: unknown): WindowInfo[];
|
|
100
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/adapters/cua-driver/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,iBAAiB,EACjB,uBAAuB,EACvB,iBAAiB,EACjB,eAAe,EAEf,iBAAiB,EAEjB,WAAW,EACX,eAAe,EACf,UAAU,EACV,UAAU,EACV,MAAM,YAAY,CAAA;AACnB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAEN,KAAK,qBAAqB,EAE1B,KAAK,aAAa,EAClB,MAAM,aAAa,CAAA;AAIpB;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,MAAM,WAAW,uBAAuB;IACvC,4EAA4E;IAC5E,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,2EAA2E;IAC3E,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,UAAU,CAAA;IAC/B,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAA;IACrB,6EAA6E;IAC7E,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;IACzB,iBAAiB;IACjB,QAAQ,CAAC,YAAY,CAAC,EAAE,qBAAqB,CAAC,cAAc,CAAC,CAAA;IAC7D,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAA;IAClC,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAA;CAChC;AAaD,qBAAa,gBAAiB,YAAW,OAAO;IAC/C,QAAQ,CAAC,YAAY,EAAE,uBAAuB,CAAA;IAC9C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;IACvC,iFAAiF;IACjF,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA4B;IACvD,6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