use crate::Spider;
pub use spider_browser::ai::agent::{Agent, AgentOptions, AgentResult};
pub use spider_browser::ai::llm_provider::{LLMConfig, LLMProviderKind};
pub use spider_browser::ai::observe::ObserveResult;
pub use spider_browser::{SpiderBrowser, SpiderBrowserOptions, SpiderPage};
#[derive(Debug, Clone)]
pub struct BrowserOptions(SpiderBrowserOptions);
impl Default for BrowserOptions {
fn default() -> Self {
Self(SpiderBrowserOptions::new(String::new()))
}
}
impl BrowserOptions {
pub fn new() -> Self {
Self::default()
}
pub fn with_browser(mut self, browser: impl Into<String>) -> Self {
self.0.browser = Some(browser.into());
self
}
pub fn with_server_url(mut self, url: impl Into<String>) -> Self {
self.0.server_url = Some(url.into());
self
}
pub fn with_stealth(mut self, level: u32) -> Self {
self.0.stealth = Some(level);
self
}
pub fn with_llm(mut self, config: LLMConfig) -> Self {
self.0.llm = Some(config);
self
}
pub fn with_captcha(mut self, mode: impl Into<String>) -> Self {
self.0.captcha = Some(mode.into());
self
}
pub fn with_country(mut self, country: impl Into<String>) -> Self {
self.0.country = Some(country.into());
self
}
pub fn with_proxy_url(mut self, proxy_url: impl Into<String>) -> Self {
self.0.proxy_url = Some(proxy_url.into());
self
}
pub fn with_record(mut self, record: bool) -> Self {
self.0.record = Some(record);
self
}
pub fn with_mode(mut self, mode: impl Into<String>) -> Self {
self.0.mode = Some(mode.into());
self
}
}
impl Spider {
pub fn browser(&self, options: Option<BrowserOptions>) -> SpiderBrowser {
let mut opts = options.unwrap_or_default().0;
opts.api_key = self.api_key.clone();
SpiderBrowser::new(opts)
}
}