Refactor API integration and enhance command handling
- Removed unused modules and updated module paths for clarity. - Added autocomplete functionality for command input in InputState. - Updated AppStateRest to include a method for checking if a turn is in flight. - Refactored subagent engine to use new API client structure. - Changed default provider from "openrouter" to "zen" with updated API keys and models. - Implemented tests for memory management and edit log functionalities. - Enhanced error handling in API requests and improved response parsing. - Updated UI components to reflect new API provider and status indicators.
This commit is contained in:
@@ -397,7 +397,17 @@ pub fn apply_action(state: &mut AppStateRest, action: Action) {
|
||||
}
|
||||
}
|
||||
TurnEvent::Error(msg) => {
|
||||
state.push_toast(Toast::new(ToastKind::Error, msg));
|
||||
let long_toast = Toast {
|
||||
kind: ToastKind::Error,
|
||||
message: msg.clone(),
|
||||
created_at: chrono::Utc::now().timestamp_millis(),
|
||||
lifetime_ms: 15000,
|
||||
};
|
||||
state.push_toast(long_toast);
|
||||
state.push_transcript(ChatMessageDisplay::new(
|
||||
crate::dto::chat::message::Role::System,
|
||||
format!("Error: {}", msg),
|
||||
));
|
||||
turn_finished = true;
|
||||
}
|
||||
TurnEvent::Done => {
|
||||
@@ -453,16 +463,13 @@ fn spawn_turn(state: &AppStateRest) {
|
||||
return;
|
||||
}
|
||||
let api_key = state.settings.api_key.clone().unwrap_or_default();
|
||||
if api_key.is_empty() {
|
||||
return;
|
||||
}
|
||||
let model = state.settings.model.clone();
|
||||
let mut tools = crate::tool::all_tools();
|
||||
tools.extend(state.mcp_manager.as_tools());
|
||||
let tool_defs = crate::tool::tool_defs(&tools);
|
||||
let ctx = state.tool_ctx();
|
||||
let mode = state.mode;
|
||||
let edit_log_path = state.edit_log.path.clone();
|
||||
let edit_session_dir = state.session_dir.clone();
|
||||
let session_id = state.session_id.clone();
|
||||
let turn_events = state.turn_events.clone();
|
||||
let in_flight_flag = state.turn_in_flight.clone();
|
||||
@@ -474,13 +481,13 @@ fn spawn_turn(state: &AppStateRest) {
|
||||
|
||||
std::thread::spawn(move || {
|
||||
let tc = TurnCtx {
|
||||
client: crate::service::openrouter::OpenRouterClient::new(api_key, model),
|
||||
client: crate::service::provider::LlmClient::new(api_key, model),
|
||||
tdefs: tool_defs,
|
||||
tools,
|
||||
ctx,
|
||||
mode,
|
||||
workspace_roots,
|
||||
edit_log_path,
|
||||
edit_log_session_dir: edit_session_dir,
|
||||
session_id,
|
||||
};
|
||||
let result = run_agent_turn(tc, &messages, &events_q);
|
||||
@@ -496,13 +503,13 @@ fn spawn_turn(state: &AppStateRest) {
|
||||
}
|
||||
|
||||
struct TurnCtx {
|
||||
client: crate::service::openrouter::OpenRouterClient,
|
||||
tdefs: Vec<crate::dto::openrouter::request::ToolDef>,
|
||||
client: crate::service::provider::LlmClient,
|
||||
tdefs: Vec<crate::dto::provider::request::ToolDef>,
|
||||
tools: Vec<Box<dyn crate::tool::Tool>>,
|
||||
ctx: crate::tool::ToolCtx,
|
||||
mode: AgentMode,
|
||||
workspace_roots: Vec<std::path::PathBuf>,
|
||||
edit_log_path: std::path::PathBuf,
|
||||
edit_log_session_dir: std::path::PathBuf,
|
||||
session_id: String,
|
||||
}
|
||||
|
||||
@@ -548,7 +555,7 @@ fn run_agent_turn(
|
||||
&tc.ctx,
|
||||
&tool_name,
|
||||
&args,
|
||||
&tc.edit_log_path,
|
||||
&tc.edit_log_session_dir,
|
||||
&tc.session_id,
|
||||
) {
|
||||
Ok(result) => (result, false, is_edit_tool),
|
||||
@@ -612,7 +619,7 @@ fn execute_one_tool(
|
||||
ctx: &crate::tool::ToolCtx,
|
||||
name: &str,
|
||||
args: &serde_json::Value,
|
||||
edit_log_path: &std::path::Path,
|
||||
session_dir: &std::path::Path,
|
||||
session_id: &str,
|
||||
) -> anyhow::Result<String> {
|
||||
for tool in tools {
|
||||
@@ -634,17 +641,27 @@ fn execute_one_tool(
|
||||
);
|
||||
format!("{:x}", hash)
|
||||
};
|
||||
let bytes_delta = if name == "write" {
|
||||
args.get("content")
|
||||
.and_then(|v| v.as_str())
|
||||
.map(|s| s.len() as i64)
|
||||
.unwrap_or(0)
|
||||
} else {
|
||||
let old = args.get("old").and_then(|v| v.as_str()).unwrap_or("");
|
||||
let new = args.get("new").and_then(|v| v.as_str()).unwrap_or("");
|
||||
(new.len() as i64 - old.len() as i64).abs()
|
||||
};
|
||||
let entry = crate::model::editlog::EditLogEntry {
|
||||
ts: chrono::Utc::now().timestamp_millis(),
|
||||
tool: name.to_string(),
|
||||
path: path.to_string(),
|
||||
reason: reason.to_string(),
|
||||
content_sha256,
|
||||
bytes_delta: result.len() as i64,
|
||||
bytes_delta,
|
||||
origin: ctx.origin.tag(),
|
||||
session_id: session_id.to_string(),
|
||||
};
|
||||
let mut el = crate::model::editlog::EditLog::new(edit_log_path);
|
||||
let mut el = crate::model::editlog::EditLog::new(session_dir);
|
||||
el.append(entry).ok();
|
||||
}
|
||||
return Ok(result);
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
pub mod tools;
|
||||
pub mod turn;
|
||||
|
||||
Reference in New Issue
Block a user