feat: nearai mcp for web search

This commit is contained in:
Coffee
2026-03-16 16:53:05 +08:00
parent 065a7498d5
commit 5c8ee16f81
3 changed files with 46 additions and 8 deletions
+2 -5
View File
@@ -34,8 +34,5 @@ trace_*.json
.claude/settings.local.json
.worktrees/
# Python cache
__pycache__/
*.pyc
*.pyo
*.pyd
# JetBrains IDE
.idea
+42
View File
@@ -0,0 +1,42 @@
use secrecy::{ExposeSecret, SecretString};
use crate::llm::LlmError;
use crate::llm::session::SessionManager;
/// Resolve the active NEAR AI bearer token.
///
/// Priority order:
/// 1. Explicit API key from resolved config
/// 2. Existing session token
/// 3. Interactive session authentication
/// 4. `NEARAI_API_KEY` from runtime environment
pub async fn resolve_nearai_bearer_token(
api_key: Option<&SecretString>,
session: &SessionManager,
) -> Result<String, LlmError> {
if let Some(api_key) = api_key {
return Ok(api_key.expose_secret().to_string());
}
if session.has_token().await {
let token = session.get_token().await?;
return Ok(token.expose_secret().to_string());
}
session.ensure_authenticated().await?;
if session.has_token().await {
let token = session.get_token().await?;
return Ok(token.expose_secret().to_string());
}
if let Ok(key) = std::env::var("NEARAI_API_KEY")
&& !key.is_empty()
{
return Ok(key);
}
Err(LlmError::AuthFailed {
provider: "nearai".to_string(),
})
}
+2 -3
View File
@@ -704,10 +704,9 @@ fn normalize_mcp_tool_arguments(tool_name: &str, value: serde_json::Value) -> se
.get("ui_lang")
.and_then(serde_json::Value::as_str)
.map(str::trim)
&& (ui_lang.is_empty() || !ui_lang.contains('-'))
{
if ui_lang.is_empty() || !ui_lang.contains('-') {
map.remove("ui_lang");
}
map.remove("ui_lang");
}
if let Some(freshness) = map