Skip to content

Commit 56f8c33

Browse files
feat: add batch computer action proxy endpoint
1 parent a35521f commit 56f8c33

6 files changed

Lines changed: 344 additions & 4 deletions

File tree

.stats.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 98
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fkernel-652441005cba60f2ada5328d8dfc60165f6ab0bb271d6b64feca250fe73dc197.yml
3-
openapi_spec_hash: f50a08ba2578efd8b756bdd920510c50
4-
config_hash: dd218aae3f852dff79e77febc2077b8e
1+
configured_endpoints: 100
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fkernel-a6d93dc291278035c96add38bb6150ec2b9ba8bbabb4676e3dbbb8444cf3b1e4.yml
3+
openapi_spec_hash: 694bcc56d94fd0ff0d1f7b0fc1dae8ba
4+
config_hash: 62e33cf2ed8fe0b4ceebba63367481ad

api.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,16 @@ Methods:
163163

164164
Types:
165165

166+
- <code><a href="./src/resources/browsers/computer.ts">ComputerGetMousePositionResponse</a></code>
166167
- <code><a href="./src/resources/browsers/computer.ts">ComputerSetCursorVisibilityResponse</a></code>
167168

168169
Methods:
169170

171+
- <code title="post /browsers/{id}/computer/batch">client.browsers.computer.<a href="./src/resources/browsers/computer.ts">batch</a>(id, { ...params }) -> void</code>
170172
- <code title="post /browsers/{id}/computer/screenshot">client.browsers.computer.<a href="./src/resources/browsers/computer.ts">captureScreenshot</a>(id, { ...params }) -> Response</code>
171173
- <code title="post /browsers/{id}/computer/click_mouse">client.browsers.computer.<a href="./src/resources/browsers/computer.ts">clickMouse</a>(id, { ...params }) -> void</code>
172174
- <code title="post /browsers/{id}/computer/drag_mouse">client.browsers.computer.<a href="./src/resources/browsers/computer.ts">dragMouse</a>(id, { ...params }) -> void</code>
175+
- <code title="post /browsers/{id}/computer/get_mouse_position">client.browsers.computer.<a href="./src/resources/browsers/computer.ts">getMousePosition</a>(id) -> ComputerGetMousePositionResponse</code>
173176
- <code title="post /browsers/{id}/computer/move_mouse">client.browsers.computer.<a href="./src/resources/browsers/computer.ts">moveMouse</a>(id, { ...params }) -> void</code>
174177
- <code title="post /browsers/{id}/computer/press_key">client.browsers.computer.<a href="./src/resources/browsers/computer.ts">pressKey</a>(id, { ...params }) -> void</code>
175178
- <code title="post /browsers/{id}/computer/scroll">client.browsers.computer.<a href="./src/resources/browsers/computer.ts">scroll</a>(id, { ...params }) -> void</code>

src/resources/browsers/browsers.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ import * as Shared from '../shared';
55
import * as ComputerAPI from './computer';
66
import {
77
Computer,
8+
ComputerBatchParams,
89
ComputerCaptureScreenshotParams,
910
ComputerClickMouseParams,
1011
ComputerDragMouseParams,
12+
ComputerGetMousePositionResponse,
1113
ComputerMoveMouseParams,
1214
ComputerPressKeyParams,
1315
ComputerScrollParams,
@@ -764,7 +766,9 @@ export declare namespace Browsers {
764766

765767
export {
766768
Computer as Computer,
769+
type ComputerGetMousePositionResponse as ComputerGetMousePositionResponse,
767770
type ComputerSetCursorVisibilityResponse as ComputerSetCursorVisibilityResponse,
771+
type ComputerBatchParams as ComputerBatchParams,
768772
type ComputerCaptureScreenshotParams as ComputerCaptureScreenshotParams,
769773
type ComputerClickMouseParams as ComputerClickMouseParams,
770774
type ComputerDragMouseParams as ComputerDragMouseParams,

src/resources/browsers/computer.ts

Lines changed: 257 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,26 @@ import { RequestOptions } from '../../internal/request-options';
77
import { path } from '../../internal/utils/path';
88

99
export class Computer extends APIResource {
10+
/**
11+
* Send an array of computer actions to execute in order on the browser instance.
12+
* Execution stops on the first error. This reduces network latency compared to
13+
* sending individual action requests.
14+
*
15+
* @example
16+
* ```ts
17+
* await client.browsers.computer.batch('id', {
18+
* actions: [{ type: 'click_mouse' }],
19+
* });
20+
* ```
21+
*/
22+
batch(id: string, body: ComputerBatchParams, options?: RequestOptions): APIPromise<void> {
23+
return this._client.post(path`/browsers/${id}/computer/batch`, {
24+
body,
25+
...options,
26+
headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),
27+
});
28+
}
29+
1030
/**
1131
* Capture a screenshot of the browser instance
1232
*
@@ -72,6 +92,19 @@ export class Computer extends APIResource {
7292
});
7393
}
7494

95+
/**
96+
* Get the current mouse cursor position on the browser instance
97+
*
98+
* @example
99+
* ```ts
100+
* const response =
101+
* await client.browsers.computer.getMousePosition('id');
102+
* ```
103+
*/
104+
getMousePosition(id: string, options?: RequestOptions): APIPromise<ComputerGetMousePositionResponse> {
105+
return this._client.post(path`/browsers/${id}/computer/get_mouse_position`, options);
106+
}
107+
75108
/**
76109
* Move the mouse cursor to the specified coordinates on the browser instance
77110
*
@@ -163,6 +196,18 @@ export class Computer extends APIResource {
163196
}
164197
}
165198

199+
export interface ComputerGetMousePositionResponse {
200+
/**
201+
* X coordinate of the cursor
202+
*/
203+
x: number;
204+
205+
/**
206+
* Y coordinate of the cursor
207+
*/
208+
y: number;
209+
}
210+
166211
/**
167212
* Generic OK response.
168213
*/
@@ -173,6 +218,216 @@ export interface ComputerSetCursorVisibilityResponse {
173218
ok: boolean;
174219
}
175220

221+
export interface ComputerBatchParams {
222+
/**
223+
* Ordered list of actions to execute. Execution stops on the first error.
224+
*/
225+
actions: Array<ComputerBatchParams.Action>;
226+
}
227+
228+
export namespace ComputerBatchParams {
229+
/**
230+
* A single computer action to execute as part of a batch. The `type` field selects
231+
* which action to perform, and the corresponding field contains the action
232+
* parameters. Exactly one action field matching the type must be provided.
233+
*/
234+
export interface Action {
235+
/**
236+
* The type of action to perform.
237+
*/
238+
type:
239+
| 'click_mouse'
240+
| 'move_mouse'
241+
| 'type_text'
242+
| 'press_key'
243+
| 'scroll'
244+
| 'drag_mouse'
245+
| 'set_cursor'
246+
| 'sleep';
247+
248+
click_mouse?: Action.ClickMouse;
249+
250+
drag_mouse?: Action.DragMouse;
251+
252+
move_mouse?: Action.MoveMouse;
253+
254+
press_key?: Action.PressKey;
255+
256+
scroll?: Action.Scroll;
257+
258+
set_cursor?: Action.SetCursor;
259+
260+
/**
261+
* Pause execution for a specified duration.
262+
*/
263+
sleep?: Action.Sleep;
264+
265+
type_text?: Action.TypeText;
266+
}
267+
268+
export namespace Action {
269+
export interface ClickMouse {
270+
/**
271+
* X coordinate of the click position
272+
*/
273+
x: number;
274+
275+
/**
276+
* Y coordinate of the click position
277+
*/
278+
y: number;
279+
280+
/**
281+
* Mouse button to interact with
282+
*/
283+
button?: 'left' | 'right' | 'middle' | 'back' | 'forward';
284+
285+
/**
286+
* Type of click action
287+
*/
288+
click_type?: 'down' | 'up' | 'click';
289+
290+
/**
291+
* Modifier keys to hold during the click
292+
*/
293+
hold_keys?: Array<string>;
294+
295+
/**
296+
* Number of times to repeat the click
297+
*/
298+
num_clicks?: number;
299+
}
300+
301+
export interface DragMouse {
302+
/**
303+
* Ordered list of [x, y] coordinate pairs to move through while dragging. Must
304+
* contain at least 2 points.
305+
*/
306+
path: Array<Array<number>>;
307+
308+
/**
309+
* Mouse button to drag with
310+
*/
311+
button?: 'left' | 'middle' | 'right';
312+
313+
/**
314+
* Delay in milliseconds between button down and starting to move along the path.
315+
*/
316+
delay?: number;
317+
318+
/**
319+
* Modifier keys to hold during the drag
320+
*/
321+
hold_keys?: Array<string>;
322+
323+
/**
324+
* Delay in milliseconds between relative steps while dragging (not the initial
325+
* delay).
326+
*/
327+
step_delay_ms?: number;
328+
329+
/**
330+
* Number of relative move steps per segment in the path. Minimum 1.
331+
*/
332+
steps_per_segment?: number;
333+
}
334+
335+
export interface MoveMouse {
336+
/**
337+
* X coordinate to move the cursor to
338+
*/
339+
x: number;
340+
341+
/**
342+
* Y coordinate to move the cursor to
343+
*/
344+
y: number;
345+
346+
/**
347+
* Modifier keys to hold during the move
348+
*/
349+
hold_keys?: Array<string>;
350+
}
351+
352+
export interface PressKey {
353+
/**
354+
* List of key symbols to press. Each item should be a key symbol supported by
355+
* xdotool (see X11 keysym definitions). Examples include "Return", "Shift",
356+
* "Ctrl", "Alt", "F5". Items in this list could also be combinations, e.g.
357+
* "Ctrl+t" or "Ctrl+Shift+Tab".
358+
*/
359+
keys: Array<string>;
360+
361+
/**
362+
* Duration to hold the keys down in milliseconds. If omitted or 0, keys are
363+
* tapped.
364+
*/
365+
duration?: number;
366+
367+
/**
368+
* Optional modifier keys to hold during the key press sequence.
369+
*/
370+
hold_keys?: Array<string>;
371+
}
372+
373+
export interface Scroll {
374+
/**
375+
* X coordinate at which to perform the scroll
376+
*/
377+
x: number;
378+
379+
/**
380+
* Y coordinate at which to perform the scroll
381+
*/
382+
y: number;
383+
384+
/**
385+
* Horizontal scroll amount. Positive scrolls right, negative scrolls left.
386+
*/
387+
delta_x?: number;
388+
389+
/**
390+
* Vertical scroll amount. Positive scrolls down, negative scrolls up.
391+
*/
392+
delta_y?: number;
393+
394+
/**
395+
* Modifier keys to hold during the scroll
396+
*/
397+
hold_keys?: Array<string>;
398+
}
399+
400+
export interface SetCursor {
401+
/**
402+
* Whether the cursor should be hidden or visible
403+
*/
404+
hidden: boolean;
405+
}
406+
407+
/**
408+
* Pause execution for a specified duration.
409+
*/
410+
export interface Sleep {
411+
/**
412+
* Duration to sleep in milliseconds.
413+
*/
414+
duration_ms: number;
415+
}
416+
417+
export interface TypeText {
418+
/**
419+
* Text to type on the browser instance
420+
*/
421+
text: string;
422+
423+
/**
424+
* Delay in milliseconds between keystrokes
425+
*/
426+
delay?: number;
427+
}
428+
}
429+
}
430+
176431
export interface ComputerCaptureScreenshotParams {
177432
region?: ComputerCaptureScreenshotParams.Region;
178433
}
@@ -353,7 +608,9 @@ export interface ComputerTypeTextParams {
353608

354609
export declare namespace Computer {
355610
export {
611+
type ComputerGetMousePositionResponse as ComputerGetMousePositionResponse,
356612
type ComputerSetCursorVisibilityResponse as ComputerSetCursorVisibilityResponse,
613+
type ComputerBatchParams as ComputerBatchParams,
357614
type ComputerCaptureScreenshotParams as ComputerCaptureScreenshotParams,
358615
type ComputerClickMouseParams as ComputerClickMouseParams,
359616
type ComputerDragMouseParams as ComputerDragMouseParams,

src/resources/browsers/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ export {
1818
} from './browsers';
1919
export {
2020
Computer,
21+
type ComputerGetMousePositionResponse,
2122
type ComputerSetCursorVisibilityResponse,
23+
type ComputerBatchParams,
2224
type ComputerCaptureScreenshotParams,
2325
type ComputerClickMouseParams,
2426
type ComputerDragMouseParams,

0 commit comments

Comments
 (0)