Skip to main content

computer_use/
lib.rs

1//! Cross-platform desktop automation for agents.
2//!
3//! The CLI and the library share [`dispatch`]: a typed [`Action`] goes in and a
4//! [`Response`] comes out. Platform backends live behind [`DesktopBackend`].
5//!
6//! # Example
7//!
8//! ```
9//! use computer_use::{dispatch, Action};
10//!
11//! let response = dispatch(Action::Wait {
12//!     ms: Some(0),
13//!     seconds: None,
14//! });
15//! assert!(response.ok);
16//! assert_eq!(response.to_value()["waited_ms"].as_u64(), Some(0));
17//! ```
18
19#![deny(unsafe_code)]
20
21pub mod adapters;
22mod attempt;
23pub mod audit;
24pub mod backend;
25pub mod browser;
26pub mod cache;
27mod doctor;
28pub mod element;
29pub mod error;
30mod foreground;
31mod image_util;
32mod input_session;
33pub mod isolation;
34pub mod keys;
35pub mod menu_path;
36pub mod overlay;
37pub mod policy;
38pub mod protocol;
39pub mod scroll;
40pub mod shortcuts;
41pub mod state;
42pub mod target;
43mod tier;
44pub mod tree;
45pub mod types;
46pub mod vision;
47pub mod window_groups;
48
49#[cfg(test)]
50pub(crate) mod test_backend;
51
52pub use backend::{create_desktop_backend, Backend, DesktopBackend};
53pub use error::{ComputerError, ErrorBody};
54pub use image_util::{
55    encode_image, image_to_screen, screen_to_image, EncodedImage, MapFormulas, MapPoint,
56    ScreenshotMap,
57};
58pub use input_session::InputSession;
59pub use keys::{parse_key_combo, parse_key_sequence, KeyCombo};
60pub use protocol::{
61    dispatch, dispatch_context, dispatch_with, handle_request_line, handle_request_line_with,
62    parse_request, Action, CallContext, Request, Response,
63};
64pub use types::{
65    parse_path, parse_region, DisplayInfo, Frame, FrontmostInfo, ImageFormat, Modifier,
66    MouseButton, Point, Region, ScrollDirection,
67};
68
69/// Restore Electron accessibility flags and stop AX observers.
70///
71/// The CLI calls this before it exits. A crash skips it, so a flag this process
72/// turned on can stay set until the target app quits. `session end` restores
73/// from the session cache in a later process.
74pub fn shutdown_sessions() {
75    backend::shutdown_sessions();
76}
77
78#[cfg(target_os = "linux")]
79pub use backend::LinuxDesktopBackend;
80#[cfg(target_os = "macos")]
81pub use backend::MacOsDesktopBackend;
82#[cfg(target_os = "windows")]
83pub use backend::WindowsDesktopBackend;