@@ -7,6 +7,26 @@ import { RequestOptions } from '../../internal/request-options';
77import { path } from '../../internal/utils/path' ;
88
99export 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+
176431export interface ComputerCaptureScreenshotParams {
177432 region ?: ComputerCaptureScreenshotParams . Region ;
178433}
@@ -353,7 +608,9 @@ export interface ComputerTypeTextParams {
353608
354609export 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 ,
0 commit comments