feat: enhance error handling in OAuth URL building and client creation; improve tool argument sanitization

This commit is contained in:
asepharyana
2026-07-12 10:23:26 +07:00
parent 0cc60c12ce
commit bb621fdff2
10 changed files with 79 additions and 43 deletions
+16 -27
View File
@@ -9,8 +9,10 @@ use crate::app::state::runtime::TurnEvent;
use crate::app::state::types::{Origin, Overlay, Toast, ToastKind};
use crate::dto::chat::message::{ChatMessage, Role};
const MAX_TOOL_ONLY_TURNS: usize = usize::MAX;
const MAX_AGENT_STEPS: usize = usize::MAX;
// Step bounds intentionally left unbounded (usize::MAX) so the agent can
// continue across as many turns as needed. Each iteration still honours
// `tc.abort_flag` and the per-call LLM timeout, so a runaway loop is
// observable and cancellable from the UI.
#[derive(Debug, Clone)]
pub enum Action {
@@ -555,19 +557,17 @@ fn generate_workspace_tree(roots: &[std::path::PathBuf]) -> String {
.git_ignore(true)
.build();
let mut count = 0;
for result in walker {
if let Ok(entry) = result {
let path = entry.path();
if let Ok(rel) = path.strip_prefix(root) {
if rel.as_os_str().is_empty() { continue; }
let is_dir = entry.file_type().map(|ft| ft.is_dir()).unwrap_or(false);
let prefix = if is_dir { "[DIR] " } else { " " };
out.push_str(&format!(" {}{}\n", prefix, rel.display()));
count += 1;
if count > 1000 {
out.push_str(" ... (truncated)\n");
break;
}
for entry in walker.flatten() {
let path = entry.path();
if let Ok(rel) = path.strip_prefix(root) {
if rel.as_os_str().is_empty() { continue; }
let is_dir = entry.file_type().map(|ft| ft.is_dir()).unwrap_or(false);
let prefix = if is_dir { "[DIR] " } else { " " };
out.push_str(&format!(" {}{}\n", prefix, rel.display()));
count += 1;
if count > 1000 {
out.push_str(" ... (truncated)\n");
break;
}
}
}
@@ -590,7 +590,6 @@ fn run_agent_turn(
) -> anyhow::Result<()> {
let mut msgs = messages.to_vec();
let mut edits_this_turn = 0u32;
let mut tool_only_rounds = 0usize;
let mut prev_shaped = false;
let tree_info = generate_workspace_tree(&tc.workspace_roots);
@@ -606,16 +605,7 @@ fn run_agent_turn(
msgs.insert(0, sys);
}
for _step in 0..MAX_AGENT_STEPS {
if tool_only_rounds >= MAX_TOOL_ONLY_TURNS {
let stop_msg = ChatMessage::user(
"Stop calling tools. Respond naturally now.".to_string(),
);
archive_message(&tc.db, &tc.session_id, &stop_msg);
msgs.push(stop_msg);
tool_only_rounds = 0;
}
loop {
let wire_msgs = if crate::app::runtime::shortsend::should_shape(msgs.len(), prev_shaped) {
let total_chars: usize = msgs.iter()
.filter_map(|m| m.content.as_deref())
@@ -728,7 +718,6 @@ fn run_agent_turn(
let content = response.content.clone().unwrap_or_default();
if has_tool_calls {
tool_only_rounds += 1;
let tool_calls = response.tool_calls.clone().unwrap_or_default();
archive_message(&tc.db, &tc.session_id, &response);
msgs.push(response);