mod actions;
mod calls;
mod cursor;
mod inputs;
mod keys;
mod opt_in;
mod person;
mod reads;
mod refs;
mod schema;
mod snapshot;
mod tabs;
mod text;
mod view;
use super::code_mode::ContextExposure;
use super::sdk_registry::ToolBundle;
use crate::browser::config::BrowserConfig;
use crate::browser::SessionBrowser;
use futures_util::future::BoxFuture;
use rho_sdk::tool::Tool;
use schema::Action;
use std::sync::Arc;
use tabs::SessionTabs;
pub(crate) fn tool_names() -> impl Iterator<Item = &'static str> {
Action::ALL.into_iter().map(Action::name)
}
pub(super) fn session_tabs(browser: SessionBrowser) -> TabsBundle {
let tabs = Arc::new(SessionTabs::new(browser.clone()));
let person: Arc<dyn crate::browser::drive::PersonTabs> = tabs.clone();
browser.drive_with(Arc::downgrade(&person));
TabsBundle { tabs }
}
pub(super) struct TabsBundle {
tabs: Arc<SessionTabs>,
}
impl TabsBundle {
pub(super) fn agent_bundles(
&self,
max_output_bytes: usize,
config: &BrowserConfig,
) -> [BrowserBundle; 2] {
let offer = Arc::new(calls::Offer::new(config));
let tools = |declared: bool| -> Vec<Arc<dyn Tool>> {
offer
.actions
.iter()
.copied()
.filter(|action| (*action == Action::Navigate) == declared)
.map(|action| {
Arc::new(calls::BrowserTool {
tabs: Arc::clone(&self.tabs),
action,
max_output_bytes,
offer: Arc::clone(&offer),
}) as Arc<dyn Tool>
})
.collect()
};
[
BrowserBundle {
tools: tools( true),
exposure: ContextExposure::Direct,
},
BrowserBundle {
tools: tools( false),
exposure: ContextExposure::Hidden,
},
]
}
}
impl ToolBundle for TabsBundle {
fn tools(&self) -> &[Arc<dyn Tool>] {
&[]
}
fn shutdown(&self) -> BoxFuture<'_, ()> {
Box::pin(self.tabs.release())
}
}
pub(super) struct BrowserBundle {
tools: Vec<Arc<dyn Tool>>,
exposure: ContextExposure,
}
impl ToolBundle for BrowserBundle {
fn tools(&self) -> &[Arc<dyn Tool>] {
&self.tools
}
fn context_exposure(&self) -> ContextExposure {
self.exposure
}
}