Skip to main content

reasonkit_web/
lib.rs

1//! ReasonKit Web - High-Performance Browser Connector
2//!
3//! A Rust-powered MCP server for browser automation, web capture, and content extraction.
4//!
5//! # Features
6//!
7//! - **CDP Integration**: Chrome DevTools Protocol client for browser automation
8//! - **MCP Server**: Model Context Protocol server for AI agent integration
9//! - **Content Extraction**: HTML parsing and structured data extraction
10//! - **WASM Support**: Browser-native execution via WebAssembly
11//!
12//! # Example
13//!
14//! ```rust,ignore
15//! use reasonkit_web::BrowserConnector;
16//!
17//! #[tokio::main]
18//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
19//!     let connector = BrowserConnector::new().await?;
20//!     let page = connector.navigate("https://example.com").await?;
21//!     let content = page.capture_content().await?;
22//!     Ok(())
23//! }
24//! ```
25
26#![cfg_attr(docsrs, feature(doc_cfg))]
27#![warn(missing_docs)]
28#![warn(clippy::all)]
29
30pub mod browser;
31pub mod buffer;
32pub mod cors;
33pub mod error;
34pub mod extraction;
35pub mod handlers;
36pub mod mcp;
37pub mod metrics;
38pub mod processing;
39pub mod shutdown;
40pub mod stripe;
41
42/// User portal for account management, settings sync, and data export.
43///
44/// Provides:
45/// - JWT-based authentication with refresh tokens
46/// - User profile management (GDPR compliant)
47/// - Settings synchronization across devices
48/// - API key generation and scoping
49/// - Multi-format data export (JSON, CSV, PDF)
50#[allow(missing_docs)] // Internal portal API - docs optional
51pub mod portal;
52
53/// Triangulated Web Research Module (CONS-006 compliant)
54///
55/// Provides cross-validated web research with 3+ source verification.
56///
57/// **"Trust, but verify. Then verify again. Then get a third opinion."**
58///
59/// # Components
60///
61/// - [`research::sources`] - Source tier classification (Tier 1/2/3)
62/// - [`research::triangulation`] - Core triangulation engine
63/// - [`research::verification`] - Verification result types
64/// - [`research::consensus`] - Consensus extraction and conflict detection
65///
66/// # Example
67///
68/// ```rust,ignore
69/// use reasonkit_web::research::{TriangulationEngine, ResearchConfig};
70///
71/// let engine = TriangulationEngine::new(ResearchConfig::default());
72/// let result = engine.research_with_urls(
73///     "What is the population of Tokyo?",
74///     &urls,
75///     &contents,
76/// );
77///
78/// assert!(result.is_verified());
79/// assert!(result.sources.len() >= 3);
80/// ```
81pub mod research;
82
83// Phase 3 Research Integrations (2026-01-18)
84#[cfg(feature = "crawler")]
85pub mod crawler;
86
87/// Crate version
88pub const VERSION: &str = env!("CARGO_PKG_VERSION");
89
90/// Crate name
91pub const NAME: &str = env!("CARGO_PKG_NAME");
92
93/// Generate a unique request ID (UUID v4)
94pub fn generate_request_id() -> String {
95    uuid::Uuid::new_v4().to_string()
96}
97
98// Re-export key components for convenience
99pub use browser::controller::BrowserController;
100pub use error::Error;
101pub use extraction::content::ContentExtractor;
102pub use extraction::links::LinkExtractor;
103pub use extraction::metadata::MetadataExtractor;
104pub use handlers::orchestrator::{orchestrator_router, OrchestratorState};
105pub use mcp::McpServer;
106
107// Triangulated Research re-exports (CONS-006 compliance)
108pub use research::{
109    ResearchConfig, ResearchResult, SourceQuality, SourceTier, TierClassifier, TriangulationEngine,
110    VerificationStatus, VerifiedSource,
111};
112
113/// Configuration defaults
114pub mod config {
115    /// Default connection timeout in milliseconds
116    pub const DEFAULT_TIMEOUT_MS: u64 = 30_000;
117
118    /// Default viewport width
119    pub const DEFAULT_VIEWPORT_WIDTH: u32 = 1920;
120
121    /// Default viewport height
122    pub const DEFAULT_VIEWPORT_HEIGHT: u32 = 1080;
123}
124
125/// Browser connector state for WASM environments
126#[cfg(target_arch = "wasm32")]
127#[wasm_bindgen]
128pub struct WasmBrowserConnector {
129    connected: bool,
130    url: String,
131}
132
133#[cfg(target_arch = "wasm32")]
134#[wasm_bindgen]
135impl WasmBrowserConnector {
136    /// Create a new WASM browser connector
137    #[wasm_bindgen(constructor)]
138    pub fn new() -> Self {
139        Self {
140            connected: false,
141            url: String::new(),
142        }
143    }
144
145    /// Check if connected
146    #[wasm_bindgen(getter)]
147    pub fn connected(&self) -> bool {
148        self.connected
149    }
150
151    /// Get current URL
152    #[wasm_bindgen(getter)]
153    pub fn url(&self) -> String {
154        self.url.clone()
155    }
156
157    /// Connect to a URL
158    pub fn connect(&mut self, url: &str) -> bool {
159        self.url = url.to_string();
160        self.connected = true;
161        true
162    }
163
164    /// Disconnect
165    pub fn disconnect(&mut self) {
166        self.connected = false;
167        self.url.clear();
168    }
169}
170
171#[cfg(target_arch = "wasm32")]
172impl Default for WasmBrowserConnector {
173    fn default() -> Self {
174        Self::new()
175    }
176}
177
178#[cfg(test)]
179mod tests {
180    use super::*;
181
182    #[test]
183    fn test_config_defaults() {
184        assert_eq!(config::DEFAULT_TIMEOUT_MS, 30_000);
185        assert_eq!(config::DEFAULT_VIEWPORT_WIDTH, 1920);
186        assert_eq!(config::DEFAULT_VIEWPORT_HEIGHT, 1080);
187    }
188}