Skip to main content

aither_agent/
browser_backend.rs

1//! Browser backend abstraction for interactive browser automation.
2
3/// Error returned by browser backend operations.
4#[derive(Debug, Clone)]
5pub struct BrowserBackendError {
6    message: String,
7}
8
9impl BrowserBackendError {
10    /// Create a new browser backend error.
11    #[must_use]
12    pub fn new(message: impl Into<String>) -> Self {
13        Self {
14            message: message.into(),
15        }
16    }
17}
18
19impl std::fmt::Display for BrowserBackendError {
20    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21        write!(f, "browser backend error: {}", self.message)
22    }
23}
24
25impl std::error::Error for BrowserBackendError {}
26
27/// Backend abstraction for browser automation runtimes.
28///
29/// Implementations may connect to local Chromium, remote CDP endpoints, or
30/// cloud browser providers.
31pub trait BrowserBackend: Send + Sync {
32    /// Returns a CDP endpoint URL for Playwright/browser clients.
33    fn cdp_endpoint(&self) -> impl Future<Output = Result<String, BrowserBackendError>> + Send;
34}
35
36/// Fixed CDP backend backed by a static endpoint string.
37#[derive(Debug, Clone)]
38pub struct StaticCdpBrowser {
39    endpoint: String,
40}
41
42impl StaticCdpBrowser {
43    /// Create a static CDP backend.
44    #[must_use]
45    pub fn new(endpoint: impl Into<String>) -> Self {
46        Self {
47            endpoint: endpoint.into(),
48        }
49    }
50}
51
52impl BrowserBackend for StaticCdpBrowser {
53    fn cdp_endpoint(&self) -> impl Future<Output = Result<String, BrowserBackendError>> {
54        std::future::ready(Ok(self.endpoint.clone()))
55    }
56}