rho-coding-agent 3.13.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 tool set carries out on the tabs it keeps,
//! whether or not the agent has the browser tools, so a tab a person opens
//! is one the agent's tools can use once it drives again.

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

/// A person's actions on a session's tabs. The session's tool set
/// implements it on the tabs it keeps and registers 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`, answering the page's cursor under the
    /// pointer after mouse input, if the page could say.
    fn input(
        &self,
        tab: String,
        input: BrowserInput,
    ) -> BoxFuture<'_, Result<Option<BrowserCursor>, 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<'_, ()>;

    /// Renders every tab at the viewport the session's browser is sized
    /// for now ([`super::SessionBrowser::viewport`]), once no agent call
    /// holds the tabs. Starts no browser: the tabs of one that closed went
    /// with it.
    fn fit(&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 tabs are gone with its tool set, as in a session that
    /// is closing.
    Closing,
    /// 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),
}