MCPcopy Create free account
hub / github.com/AI45Lab/Code / get_or_init_pool

Method get_or_init_pool

core/src/tools/builtin/web_search.rs:25–58  ·  view source on GitHub ↗

Get or create the BrowserPool for headless browser engines

(
        &self,
        headless_config: Option<&HeadlessConfig>,
    )

Source from the content-addressed store, hash-verified

23
24 /// Get or create the BrowserPool for headless browser engines
25 fn get_or_init_pool(
26 &self,
27 headless_config: Option<&HeadlessConfig>,
28 ) -> Option<Arc<BrowserPool>> {
29 let config = headless_config?;
30
31 let pool_config = BrowserPoolConfig {
32 max_tabs: config.max_tabs,
33 headless: true,
34 chrome_path: if config.backend == BrowserBackend::Chrome {
35 config.browser_path.clone()
36 } else {
37 None
38 },
39 lightpanda_path: if config.backend == BrowserBackend::Lightpanda {
40 config.browser_path.clone()
41 } else {
42 None
43 },
44 proxy_url: config.proxy_url.clone(),
45 launch_args: config.launch_args.clone(),
46 backend: match config.backend {
47 BrowserBackend::Chrome => a3s_search::BrowserBackend::Chrome,
48 BrowserBackend::Lightpanda => a3s_search::BrowserBackend::Lightpanda,
49 },
50 };
51
52 let pool = BrowserPool::new(pool_config);
53 let pool = Arc::new(pool);
54
55 // Try to set, but if already set, use the existing one
56 self.browser_pool.get_or_init(|| pool.clone());
57 self.browser_pool.get().cloned()
58 }
59}
60
61impl Default for WebSearchTool {

Callers 1

executeMethod · 0.80

Calls 2

cloneMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected