Skip to main content

ComputerUseDriver

Struct ComputerUseDriver 

Source
pub struct ComputerUseDriver { /* private fields */ }
Expand description

Shared driver all seven computer-use tools hold an Arc<> to.

Implementations§

Source§

impl ComputerUseDriver

Source

pub fn new(backend: Backend) -> Self

Source

pub fn backend(&self) -> Backend

Source

pub fn ensure_alive(&self) -> Result<(), String>

Cheap mid-call liveness check. Tools call this first inside execute(); if the display went away after registration, they return a clean error instead of hanging on subprocess dispatch.

§Errors

The display probe not reaching the backend — a detached session, a changed DISPLAY. The message names the backend, because that is the only thing the caller can act on.

Source

pub async fn ensure_alive_async(&self) -> Result<(), String>

Async form of Self::ensure_alive. The X11 display probe spawns a xdpyinfo/xdotool subprocess and blocks on its exit; on the async tool path that would block a worker, so run it on the blocking pool (#34).

§Errors

Self::ensure_alive’s, plus the blocking task itself failing to run — reported distinctly, since “the probe never ran” is not the same claim as “the display is gone”.

Source

pub fn scale_coords( &self, x: i32, y: i32, screenshot_id: Option<u64>, ) -> Result<(i32, i32), String>

Translate model-space coords to screen-space using the metadata registered for screenshot_id (or the latest if None).

§Errors

A poisoned registry lock; a screenshot_id no longer in the registry, which after SCREENSHOT_REGISTRY_CAPACITY newer frames means evicted, so the message says to capture a fresh one; and no screenshot registered at all when screenshot_id is None. Out-of-frame coords are not an error — they are clamped into the frame’s bounds.

Source

pub fn register_screenshot( &self, scale_factor: f64, offset_x: i32, offset_y: i32, width: u32, height: u32, kind: String, ) -> u64

Allocate a fresh registry id and record metadata.

Source

pub async fn capture( &self, spec: ScreenshotSpec, token: &CancellationToken, ) -> Result<CaptureResult>

Capture and return the encoded result. Respects cancellation via token.cancelled() races in the subprocess wait.

§Errors

An unreachable display, resolving the private scratch dir, the capture subprocess failing or timing out, the downscale, and reading the frame back. Cancellation via token also arrives as an Err — at the capture, the downscale, or the read — so a caller must not read one as a broken display. Temp files are removed on every path.

Source

pub async fn capture_focused_for_autoshot( &self, token: &CancellationToken, ) -> Option<(String, String)>

Convenience for click/type/key tools: capture the focused window and return (summary, base64_png) for inclusion in the tool’s auto-screenshot. Best-effort — on error returns None and the caller can fall back to a screenshot-less outcome.

Source

pub async fn check_cursor_landed(&self, sx: i32, sy: i32) -> Option<String>

X11-only: verify the cursor actually landed where xdotool was told to move it. Returns Some(warning) if the cursor ended up more than CURSOR_LANDED_TOLERANCE_PX away (focus change, window moved, WM rejected the move). None if within tolerance or the probe itself failed (best-effort — never blocks the click).

Source§

impl ComputerUseDriver

Source

pub async fn click( &self, sx: i32, sy: i32, button: &str, token: &CancellationToken, ) -> Result<()>

Click at the given SCREEN coordinates (already scaled by scale_coords). button is "left" | "middle" | "right".

§Errors

A backend that is neither X11 nor Wayland, a Wayland session with no ydotool, the tool itself failing or exiting nonzero, and cancellation via token. An unrecognized button is not an error — it falls back to left.

Source

pub async fn type_text( &self, text: &str, token: &CancellationToken, ) -> Result<()>

Type text at the current focus. Per-keystroke delay from TYPE_KEY_DELAY_MS — empirically needed for slow Electron / web targets that drop characters at lower rates.

§Errors

A backend that is neither X11 nor Wayland, a Wayland session with neither wtype nor ydotool, the tool failing or exiting nonzero, and cancellation via token. A cancelled call may have typed part of text already — there is no way to unsend keystrokes.

Source

pub async fn press_key( &self, key: &str, token: &CancellationToken, ) -> Result<()>

Press a key (or key combination like "ctrl+shift+t").

§Errors

A backend that is neither X11 nor Wayland, a Wayland session with neither wtype nor ydotool, the tool failing or exiting nonzero, and cancellation via token. A key the tool does not recognize surfaces as that tool’s nonzero exit, not as a check here.

Source

pub async fn scroll( &self, direction: &str, amount: i32, token: &CancellationToken, ) -> Result<()>

Scroll amount ticks in direction (“up” / “down”).

§Errors

A backend that is neither X11 nor Wayland, a Wayland session with no ydotool, the tool failing or exiting nonzero, and cancellation via token. Any direction other than "up" is treated as down rather than rejected.

Source

pub async fn mouse_move( &self, sx: i32, sy: i32, token: &CancellationToken, ) -> Result<()>

Move the mouse cursor to SCREEN coords (already scaled).

§Errors

A backend that is neither X11 nor Wayland, a Wayland session with no ydotool, the tool failing or exiting nonzero, and cancellation via token. Coordinates off the screen are the tool’s business, not checked here.

Source

pub async fn list_windows( &self, _token: &CancellationToken, ) -> Result<Vec<String>>

List visible window titles. X11 only; Wayland has no portable enumeration primitive.

§Errors

Any backend other than X11, and the xdotool search that lists window ids failing. A window whose title cannot be read afterwards is skipped rather than failing the call, so the list can be shorter than the search found.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more