Skip to content

Commit aa7a2fb

Browse files
authored
feat(cua-computer): browser action family over v2 (#123960)
* feat(cua-computer): add browser action family * refactor(cua-computer): split browser action files * refactor(cua-computer): move the shared act-params type to the leaf module * fix(cua-computer): carry the contract params import with the moved type
1 parent 103e1a4 commit aa7a2fb

17 files changed

Lines changed: 2068 additions & 262 deletions

‎docs/nodes/computer-use.md‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ The built-in `computer` tool takes one action per call. Coordinates are non-nega
3636

3737
Providers with the v2 window/element family can additionally expose `list_apps`, `list_windows`, `get_accessibility_tree`, `get_cursor_position`, `get_window_state`, `launch_app`, `kill_app`, `bring_to_front`, `set_value`, `zoom`, `escalate_scope`, and `invoke_menu`. The provider descriptor is authoritative; unavailable actions are omitted rather than emulated through another provider.
3838

39+
The CUA provider also exposes the v2 browser family: `get_browser_state`, `browser_prepare`, `browser_navigate`, `browser_click`, `browser_type`, `browser_dialog`, `browser_set_input_files`, `browser_download`, and `browser_pointer`. Bind a discovered native browser window with `get_browser_state`, then use the returned opaque `browserRef`, `pageRef`, observation, and element references. These references belong to one Computer Use execution and driver generation; navigation invalidates page-element observations, and a driver restart invalidates the complete browser reference set.
40+
3941
Modifier keys ride the `text` field on click and scroll actions (`shift`, `ctrl`, `alt`, `cmd`). After an input action the tool returns a fresh screenshot so the model can observe the result. If more than one computer-capable node is connected, pass `node` explicitly.
4042

4143
Screenshots are kept **model-only**: they are never auto-delivered to the chat channel. Treat all on-screen content as untrusted input; the tool warns the model not to follow on-screen instructions that conflict with the user's request.
@@ -52,7 +54,13 @@ The app waits until the private socket accepts connections before advertising CU
5254

5355
The embedded CUA daemon runs in unrestricted mode because bounded CUA grants require exact launch-time resources and cannot represent OpenClaw's runtime-discovered windows and elements. OpenClaw command arming, pairing approval, and tool policy are the authoritative authorization gate, identical to the shipped Peekaboo fulfiller. The app owns the daemon and its macOS TCC identity, and the daemon accepts local connections only through an owner-only socket directory.
5456

55-
The CUA descriptor advertises window and element targets, background and foreground delivery, screenshots, and accessibility observations. Peekaboo remains the default in this release and advertises the existing coordinate-action family; its v2 adapter is separate work.
57+
The CUA descriptor advertises window, element, and browser targets; background and foreground delivery; and image, accessibility, and browser observations. Peekaboo remains the default in this release and advertises only the action families its native adapter implements.
58+
59+
#### Browser profiles
60+
61+
`browser_prepare` can launch a separate driver-owned Chromium process with a new ephemeral profile or a named isolated profile. It never modifies, copies, terminates, or attaches to the selected browser's existing profile. Existing-profile/CDP attachment remains unavailable because it requires the driver's protected embedding-host consent and revocation path; Gateway approval and `computer.act` arming do not substitute for that local consent.
62+
63+
Browser targets, pages, page elements, and dialogs are opaque capabilities. Retake browser state after navigation, reconnect, or a stale-reference refusal. The adapter never returns provider-native CDP target IDs, tab IDs, or page refs to the model.
5664

5765
### Windows and Linux (experimental, direct SDK)
5866

@@ -93,6 +101,7 @@ The `cua-computer` fulfiller surfaces typed error codes in the tool result and n
93101
| `COMPUTER_DRIVER_UNAVAILABLE` | The CUA runtime cannot initialize, the macOS app-owned endpoint is absent, or the desktop permissions/session are unavailable. | On macOS, verify CUA is selected and the bundled driver is ready; on Windows/Linux, run `openclaw node run` inside the interactive desktop session. Reinstall OpenClaw if the pinned runtime is missing. |
94102
| `COMPUTER_REFUSED_<code>` | The driver refused the action with a structured code such as `background_unavailable`, `background_occluded`, or `foreground_unavailable` (KDE/KWin Wayland). | Bring the target window forward, switch to X11, or use a supported compositor. See the compatibility notes above. |
95103
| `COMPUTER_STALE_FRAME` | The coordinates referenced a screenshot that is no longer current (context compaction, a display geometry change, or a reference-width change). | Take a fresh `screenshot` before the coordinate action. |
104+
| `COMPUTER_STALE_OBSERVATION` | A window or browser reference belongs to an older observation, navigation, execution, or driver generation. | Run `get_window_state` or `get_browser_state` again and retry with the new opaque references. |
96105
| `COMPUTER_UNSUPPORTED_ACTION` | An action this fulfiller cannot faithfully deliver: `hold_key`, `left_mouse_down`, `left_mouse_up`, or modifier-held click/drag/scroll. | Use a supported action. The typed CUA Driver desktop contract has no held-input or modifier argument for these calls. |
97106
| `COMPUTER_UNSUPPORTED_DISPLAY` | A non-primary `screenIndex`, a capture/screen geometry mismatch, or a cursor outside the primary display. | Drive the primary display only. |
98107
| `COMPUTER_UNSUPPORTED_KEY` | A `key` value the driver cannot reproduce reliably: a digit or punctuation key whose shift state is layout-dependent, or an unknown key. | Send that text through the `type` action instead. |
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
import type { ComputerActParams } from "openclaw/plugin-sdk/computer-use";
2+
import type { CuaDriverSession } from "./driver-client.js";
3+
import {
4+
resolveBrowserElementRef,
5+
resolveBrowserObservation,
6+
resolveBrowserRef,
7+
resolveElementRef,
8+
resolveObservation,
9+
resolvePageRef,
10+
resolveWindowRef,
11+
verifyGeneration,
12+
type CuaFrameState,
13+
} from "./frame.js";
14+
15+
export type CuaComputerActParams = {
16+
action: ComputerActParams["action"];
17+
displayFrameId?: string;
18+
x?: number;
19+
y?: number;
20+
fromX?: number;
21+
fromY?: number;
22+
text?: string;
23+
keys?: string;
24+
modifiers?: string;
25+
scrollDirection?: "up" | "down" | "left" | "right";
26+
scrollAmount?: number;
27+
durationMs?: number;
28+
screenIndex?: number;
29+
refWidth?: number;
30+
windowRef?: string;
31+
elementRef?: string;
32+
observationId?: string;
33+
deliveryMode?: "background" | "foreground";
34+
query?: string;
35+
depth?: number;
36+
maxElements?: number;
37+
app?: string;
38+
value?: string;
39+
path?: string[];
40+
browserRef?: string;
41+
pageRef?: string;
42+
snapshotFormat?: "dom_refs_v1" | "semantic_v2";
43+
continuation?: string;
44+
includeScreenshot?: boolean;
45+
profile?: "isolated_new" | "isolated_named";
46+
profileName?: string;
47+
url?: string;
48+
inputRoute?: "trusted" | "dom_event";
49+
mode?: "insert_text" | "keystrokes";
50+
replace?: boolean;
51+
dialogAction?: "inspect" | "accept" | "dismiss";
52+
dialogRef?: string;
53+
promptText?: string;
54+
files?: string[];
55+
destinationRoot?: string;
56+
pointerAction?: "hover" | "right_click" | "double_click" | "scroll" | "drag";
57+
destinationElementRef?: string;
58+
toX?: number;
59+
toY?: number;
60+
deltaX?: number;
61+
deltaY?: number;
62+
x1?: number;
63+
y1?: number;
64+
x2?: number;
65+
y2?: number;
66+
reason?:
67+
| "ax_tree_pixel_mismatch"
68+
| "background_delivery_failed"
69+
| "foreground_ineffective"
70+
| "no_window_target"
71+
| "other";
72+
};
73+
74+
export function requireWindowTarget(
75+
driver: CuaDriverSession,
76+
state: CuaFrameState,
77+
params: CuaComputerActParams,
78+
) {
79+
verifyGeneration(state, driver.generation);
80+
if (!params.windowRef) {
81+
throw new Error(`COMPUTER_INVALID_REQUEST: windowRef is required for ${params.action}`);
82+
}
83+
return {
84+
ref: params.windowRef,
85+
target: resolveWindowRef(state, params.windowRef),
86+
};
87+
}
88+
89+
function observationTarget(state: CuaFrameState, params: CuaComputerActParams, windowRef: string) {
90+
if (!params.observationId) {
91+
throw new Error(`COMPUTER_STALE_OBSERVATION: observationId is required for ${params.action}`);
92+
}
93+
return resolveObservation(state, params.observationId, windowRef);
94+
}
95+
96+
export function elementArgs(
97+
state: CuaFrameState,
98+
params: CuaComputerActParams,
99+
windowRef: string,
100+
): Record<string, unknown> | undefined {
101+
if (!params.elementRef) {
102+
return undefined;
103+
}
104+
const observation = observationTarget(state, params, windowRef);
105+
const element = resolveElementRef(observation, params.elementRef);
106+
return element.elementToken
107+
? { element_token: element.elementToken }
108+
: {
109+
element_index: element.elementIndex,
110+
...(element.snapshotId ? { snapshot_id: element.snapshotId } : {}),
111+
};
112+
}
113+
114+
export function browserTarget(
115+
driver: CuaDriverSession,
116+
state: CuaFrameState,
117+
params: CuaComputerActParams,
118+
) {
119+
verifyGeneration(state, driver.generation);
120+
if (!params.browserRef || !params.pageRef) {
121+
throw new Error(
122+
`COMPUTER_INVALID_REQUEST: browserRef and pageRef are required for ${params.action}`,
123+
);
124+
}
125+
const browser = resolveBrowserRef(state, params.browserRef);
126+
const page = resolvePageRef(state, params.browserRef, params.pageRef);
127+
return {
128+
browserRef: params.browserRef,
129+
pageRef: params.pageRef,
130+
targetId: browser.targetId,
131+
tabId: page.tabId,
132+
};
133+
}
134+
135+
export function browserElement(
136+
state: CuaFrameState,
137+
params: CuaComputerActParams,
138+
target: { browserRef: string; pageRef: string },
139+
elementRef = params.elementRef,
140+
): string | undefined {
141+
if (!elementRef) {
142+
return undefined;
143+
}
144+
if (!params.observationId) {
145+
throw new Error(`COMPUTER_STALE_OBSERVATION: observationId is required for ${params.action}`);
146+
}
147+
const observation = resolveBrowserObservation(
148+
state,
149+
params.observationId,
150+
target.browserRef,
151+
target.pageRef,
152+
);
153+
return resolveBrowserElementRef(observation, elementRef);
154+
}
155+
156+
export function windowPointArgs(
157+
state: CuaFrameState,
158+
params: CuaComputerActParams,
159+
windowRef: string,
160+
point: { x?: number; y?: number },
161+
label: string,
162+
): Record<string, unknown> {
163+
if (point.x === undefined || point.y === undefined) {
164+
throw new Error(`COMPUTER_INVALID_REQUEST: ${label} coordinates are required`);
165+
}
166+
const observation = observationTarget(state, params, windowRef);
167+
return {
168+
x: point.x,
169+
y: point.y,
170+
...(observation.fromZoom ? { from_zoom: true } : {}),
171+
};
172+
}

0 commit comments

Comments
 (0)