feat: web_fetch and web_search tools (Brave, SearXNG)
This commit is contained in:
1 parent
846756c0bd
commit
45d8a44b53
7 files changed
+683
-17
No files matched your search
@@ -138,10 +138,28 @@ struct Config {
|
||||
/// confine child processes: mode = "on", backend, network, rw, ro, env_allow
|
||||
sandbox: Option<hx_core::sandbox::Cfg>,
|
||||
lsp: Option<LspCfg>,
|
||||
/// web_search backend: search = "brave" (default, key in $BRAVE_API_KEY) | "searxng", searxng_url
|
||||
web: Option<WebCfg>,
|
||||
/// subprocess extensions (JSON-RPC over stdio); global and project lists are concatenated
|
||||
extensions: Vec<hx_core::ext::ExtCfg>,
|
||||
}
|
||||
|
||||
#[derive(Default, Clone, serde::Deserialize)]
|
||||
#[serde(default, deny_unknown_fields)]
|
||||
struct WebCfg {
|
||||
search: Option<String>,
|
||||
searxng_url: Option<String>,
|
||||
}
|
||||
|
||||
fn web_search(cfg: &Config) -> Option<hx_tools::web::Search> {
|
||||
let w = cfg.web.clone().unwrap_or_default();
|
||||
hx_tools::web::Search::pick(
|
||||
w.search.as_deref(),
|
||||
std::env::var("BRAVE_API_KEY").ok(),
|
||||
w.searxng_url,
|
||||
)
|
||||
}
|
||||
|
||||
#[derive(Default, Clone, serde::Deserialize)]
|
||||
#[serde(default, deny_unknown_fields)]
|
||||
struct LspCfg {
|
||||
@@ -187,6 +205,7 @@ impl Config {
|
||||
system_prompt: o.system_prompt.or(c.system_prompt),
|
||||
sandbox: o.sandbox.or(c.sandbox),
|
||||
lsp: o.lsp.or(c.lsp),
|
||||
web: o.web.or(c.web),
|
||||
extensions: [c.extensions, o.extensions].concat(),
|
||||
};
|
||||
}
|
||||
@@ -439,6 +458,7 @@ async fn main() -> Result<()> {
|
||||
hx_lens::manager::default_servers(),
|
||||
));
|
||||
let mut reg = hx_tools::registry();
|
||||
hx_tools::web::register(&mut reg, web_search(&cfg));
|
||||
hub.register(&mut reg);
|
||||
reg.add(hx_lens::LspTool::new(mgr.clone()));
|
||||
if cfg.codemode.unwrap_or(false) {
|
||||
@@ -624,6 +644,7 @@ async fn main() -> Result<()> {
|
||||
let last = last.filter(|l| l.provider == kind);
|
||||
let last_effort = last.as_ref().and_then(|l| l.effort);
|
||||
let last_model = last.map(|l| l.model);
|
||||
let search = web_search(&cfg);
|
||||
let model = cli.model.or(cfg.model).or(last_model).unwrap_or_else(|| {
|
||||
match kind {
|
||||
Kind::Claude => cfg.claude_model.clone(),
|
||||
@@ -659,12 +680,9 @@ async fn main() -> Result<()> {
|
||||
cwd: cwd.clone(),
|
||||
state: Default::default(),
|
||||
};
|
||||
let (mut agent, abort) = Agent::new(
|
||||
provider(kind)?,
|
||||
hx_tools::registry(),
|
||||
Session::open(&path)?,
|
||||
cx,
|
||||
);
|
||||
let mut tools = hx_tools::registry();
|
||||
hx_tools::web::register(&mut tools, search);
|
||||
let (mut agent, abort) = Agent::new(provider(kind)?, tools, Session::open(&path)?, cx);
|
||||
let effort = last_effort
|
||||
.filter(|e| hx_ai::Effort::levels(kind).contains(e))
|
||||
.unwrap_or(hx_ai::Effort::default_for(kind));
|
||||
|
||||
Reference in new issue
Block a user