rho-coding-agent 3.10.0

A fast Rust agent harness with a small footprint and opinionated defaults
Documentation
//! A person driving a session's browser from a client: what they do to its
//! tabs, which the session's browser tools carry out on the tabs they keep,
//! so a tab a person opens is one the agent can use once it drives again.

use futures_util::future::BoxFuture;
use rho_protocol::{BrowserDestination, BrowserInput, BrowserTabAction};

/// A person's actions on a session's tabs. The session's browser tools
/// implement it on their tabs and register it with the session's
/// [`super::SessionBrowser`]. Each action runs at once, without waiting for
/// the agent, which waits while a person drives, and leaves the session's
/// [`super::view::BrowserView`] showing its tabs as they are after it.
pub(crate) trait PersonTabs: Send + Sync {
    /// Sends `input` to tab `tab`.
    fn input(&self, tab: String, input: BrowserInput) -> BoxFuture<'_, Result<(), Refused>>;

    /// Starts tab `tab` loading `to`, answering once it has started.
    fn navigate(&self, tab: String, to: BrowserDestination) -> BoxFuture<'_, Result<(), Refused>>;

    /// Opens, closes or switches to a tab, answering the id of a tab it
    /// opened.
    fn tab(&self, action: BrowserTabAction) -> BoxFuture<'_, Result<Option<String>, Refused>>;

    /// Closes the session's tabs and their browser context.
    fn close(&self) -> BoxFuture<'_, ()>;

    /// Keeps the session's view up to date with what the person's driving
    /// does to its tabs, such as a page retitling itself or opening a
    /// popup, until the agent drives again or the browser closes.
    fn follow(&self) -> BoxFuture<'_, ()>;
}

/// Why a person's action was refused.
#[derive(Debug, PartialEq, Eq)]
pub(crate) enum Refused {
    /// The agent drives the browser: the person has not taken it over.
    NotDriver,
    /// The session's browser tools are not running, as in a session that
    /// is closing.
    NoTools,
    /// The session has no such tab.
    NoTab(String),
    /// The action was not one to carry out, as this says, such as a URL
    /// the browser tools refuse or a tab past the session's limit.
    Invalid(String),
    /// The browser failed, as this says.
    Browser(String),
}