pub struct ComputerUseDriver { /* private fields */ }Expand description
Shared driver all seven computer-use tools hold an Arc<> to.
Implementations§
Source§impl ComputerUseDriver
impl ComputerUseDriver
pub fn new(backend: Backend) -> Self
pub fn backend(&self) -> Backend
Sourcepub fn ensure_alive(&self) -> Result<(), String>
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.
Sourcepub async fn ensure_alive_async(&self) -> Result<(), String>
pub async fn ensure_alive_async(&self) -> Result<(), String>
Async form of [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).
Sourcepub fn scale_coords(
&self,
x: i32,
y: i32,
screenshot_id: Option<u64>,
) -> Result<(i32, i32), String>
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).
Sourcepub fn register_screenshot(
&self,
scale_factor: f64,
offset_x: i32,
offset_y: i32,
width: u32,
height: u32,
kind: String,
) -> u64
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.
Sourcepub async fn capture(
&self,
spec: ScreenshotSpec,
token: &CancellationToken,
) -> Result<CaptureResult>
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.
Sourcepub async fn capture_focused_for_autoshot(
&self,
token: &CancellationToken,
) -> Option<(String, String)>
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.
Sourcepub async fn check_cursor_landed(&self, sx: i32, sy: i32) -> Option<String>
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
impl ComputerUseDriver
Sourcepub async fn click(
&self,
sx: i32,
sy: i32,
button: &str,
token: &CancellationToken,
) -> Result<()>
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".
Sourcepub async fn type_text(
&self,
text: &str,
token: &CancellationToken,
) -> Result<()>
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.
Sourcepub async fn press_key(
&self,
key: &str,
token: &CancellationToken,
) -> Result<()>
pub async fn press_key( &self, key: &str, token: &CancellationToken, ) -> Result<()>
Press a key (or key combination like "ctrl+shift+t").
Sourcepub async fn scroll(
&self,
direction: &str,
amount: i32,
token: &CancellationToken,
) -> Result<()>
pub async fn scroll( &self, direction: &str, amount: i32, token: &CancellationToken, ) -> Result<()>
Scroll amount ticks in direction (“up” / “down”).
Sourcepub async fn mouse_move(
&self,
sx: i32,
sy: i32,
token: &CancellationToken,
) -> Result<()>
pub async fn mouse_move( &self, sx: i32, sy: i32, token: &CancellationToken, ) -> Result<()>
Move the mouse cursor to SCREEN coords (already scaled).
Sourcepub async fn list_windows(
&self,
_token: &CancellationToken,
) -> Result<Vec<String>>
pub async fn list_windows( &self, _token: &CancellationToken, ) -> Result<Vec<String>>
List visible window titles. X11 only; Wayland has no portable enumeration primitive.
Auto Trait Implementations§
impl !Freeze for ComputerUseDriver
impl RefUnwindSafe for ComputerUseDriver
impl Send for ComputerUseDriver
impl Sync for ComputerUseDriver
impl Unpin for ComputerUseDriver
impl UnsafeUnpin for ComputerUseDriver
impl UnwindSafe for ComputerUseDriver
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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