refactor: improve code formatting and structure across multiple files

This commit is contained in:
mai1015 2026-02-16 03:35:03 -05:00 committed by Chummy
parent b341fdb368
commit dc5e14d7d2
6 changed files with 24 additions and 16 deletions

View file

@ -286,7 +286,7 @@ impl Agent {
for msg in self.history.drain(..) {
match &msg {
ConversationMessage::Chat(chat) if chat.role == "system" => {
system_messages.push(msg)
system_messages.push(msg);
}
_ => other_messages.push(msg),
}
@ -655,7 +655,7 @@ mod tests {
let provider = Box::new(MockProvider {
responses: Mutex::new(vec![
crate::providers::ChatResponse {
text: Some("".into()),
text: Some(String::new()),
tool_calls: vec![crate::providers::ToolCall {
id: "tc1".into(),
name: "echo".into(),
@ -690,12 +690,9 @@ mod tests {
let response = agent.turn("hi").await.unwrap();
assert_eq!(response, "done");
assert!(matches!(
agent
.history()
.iter()
.find(|msg| matches!(msg, ConversationMessage::ToolResults(_))),
Some(_)
));
assert!(agent
.history()
.iter()
.any(|msg| matches!(msg, ConversationMessage::ToolResults(_))));
}
}

View file

@ -1,3 +1,4 @@
#[allow(clippy::module_inception)]
pub mod agent;
pub mod dispatcher;
pub mod loop_;

View file

@ -72,7 +72,10 @@ enum NativeContentOut {
input: serde_json::Value,
},
#[serde(rename = "tool_result")]
ToolResult { tool_use_id: String, content: String },
ToolResult {
tool_use_id: String,
content: String,
},
}
#[derive(Debug, Serialize)]

View file

@ -356,9 +356,11 @@ impl Provider for OpenRouterProvider {
model: &str,
temperature: f64,
) -> anyhow::Result<ProviderChatResponse> {
let api_key = self.api_key.as_ref().ok_or_else(|| anyhow::anyhow!(
let api_key = self.api_key.as_ref().ok_or_else(|| {
anyhow::anyhow!(
"OpenRouter API key not set. Run `zeroclaw onboard` or set OPENROUTER_API_KEY env var."
))?;
)
})?;
let tools = Self::convert_tools(request.tools);
let native_request = NativeChatRequest {

View file

@ -108,7 +108,8 @@ pub trait Provider: Send + Sync {
model: &str,
temperature: f64,
) -> anyhow::Result<String> {
self.chat_with_system(None, message, model, temperature).await
self.chat_with_system(None, message, model, temperature)
.await
}
/// One-shot chat with optional system prompt.

View file

@ -74,7 +74,7 @@ pub fn all_tools(
browser_config: &crate::config::BrowserConfig,
http_config: &crate::config::HttpRequestConfig,
workspace_dir: &std::path::Path,
agents: &HashMap<String, DelegateAgentConfig>,
agents: &HashMap<String, DelegateAgentConfig, S>,
fallback_api_key: Option<&str>,
config: &crate::config::Config,
) -> Vec<Box<dyn Tool>> {
@ -104,7 +104,7 @@ pub fn all_tools_with_runtime(
browser_config: &crate::config::BrowserConfig,
http_config: &crate::config::HttpRequestConfig,
workspace_dir: &std::path::Path,
agents: &HashMap<String, DelegateAgentConfig>,
agents: &HashMap<String, DelegateAgentConfig, S>,
fallback_api_key: Option<&str>,
config: &crate::config::Config,
) -> Vec<Box<dyn Tool>> {
@ -170,8 +170,12 @@ pub fn all_tools_with_runtime(
// Add delegation tool when agents are configured
if !agents.is_empty() {
let delegate_agents: HashMap<String, DelegateAgentConfig> = agents
.iter()
.map(|(name, cfg)| (name.clone(), cfg.clone()))
.collect();
tools.push(Box::new(DelegateTool::new(
agents.clone(),
delegate_agents,
fallback_api_key.map(String::from),
)));
}