fix: don't redact tool calls (#4589)
This commit is contained in:
@@ -1,10 +1,11 @@
|
|||||||
use anstream::println;
|
use anstream::println;
|
||||||
use bat::WrappingMode;
|
use bat::WrappingMode;
|
||||||
use console::{style, Color};
|
use console::{measure_text_width, style, Color, Term};
|
||||||
use goose::config::Config;
|
use goose::config::Config;
|
||||||
use goose::conversation::message::{Message, MessageContent, ToolRequest, ToolResponse};
|
use goose::conversation::message::{Message, MessageContent, ToolRequest, ToolResponse};
|
||||||
use goose::providers::pricing::get_model_pricing;
|
use goose::providers::pricing::get_model_pricing;
|
||||||
use goose::providers::pricing::parse_model_id;
|
use goose::providers::pricing::parse_model_id;
|
||||||
|
use goose::utils::safe_truncate;
|
||||||
use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
|
use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
|
||||||
use mcp_core::tool::ToolCall;
|
use mcp_core::tool::ToolCall;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
@@ -539,22 +540,22 @@ fn print_markdown(content: &str, theme: Theme) {
|
|||||||
|
|
||||||
const INDENT: &str = " ";
|
const INDENT: &str = " ";
|
||||||
|
|
||||||
fn get_tool_params_max_length() -> usize {
|
fn print_value_with_prefix(prefix: &String, value: &Value, debug: bool) {
|
||||||
Config::global()
|
let prefix_width = measure_text_width(prefix.as_str());
|
||||||
.get_param::<usize>("GOOSE_CLI_TOOL_PARAMS_TRUNCATION_MAX_LENGTH")
|
print!("{}", prefix);
|
||||||
.ok()
|
print_value(value, debug, prefix_width)
|
||||||
.unwrap_or(40)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_value(value: &Value, debug: bool) {
|
fn print_value(value: &Value, debug: bool, reserve_width: usize) {
|
||||||
|
let max_width = Term::stdout()
|
||||||
|
.size_checked()
|
||||||
|
.map(|(_h, w)| (w as usize).saturating_sub(reserve_width));
|
||||||
let formatted = match value {
|
let formatted = match value {
|
||||||
Value::String(s) => {
|
Value::String(s) => match (max_width, debug) {
|
||||||
if !debug && s.len() > get_tool_params_max_length() {
|
(Some(w), false) if s.len() > w => style(safe_truncate(s, w)),
|
||||||
style(format!("[REDACTED: {} chars]", s.len())).yellow()
|
_ => style(s.to_string()),
|
||||||
} else {
|
|
||||||
style(s.to_string()).green()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
.green(),
|
||||||
Value::Number(n) => style(n.to_string()).yellow(),
|
Value::Number(n) => style(n.to_string()).yellow(),
|
||||||
Value::Bool(b) => style(b.to_string()).yellow(),
|
Value::Bool(b) => style(b.to_string()).yellow(),
|
||||||
Value::Null => style("null".to_string()).dim(),
|
Value::Null => style("null".to_string()).dim(),
|
||||||
@@ -596,9 +597,11 @@ fn print_params(value: &Value, depth: usize, debug: bool) {
|
|||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
let joined_values = values.join(", ");
|
let joined_values = values.join(", ");
|
||||||
print!("{}{}: ", indent, style(key).dim());
|
print_value_with_prefix(
|
||||||
// Use print_value to handle truncation consistently
|
&format!("{}{}: ", indent, style(key).dim()),
|
||||||
print_value(&Value::String(joined_values), debug);
|
&Value::String(joined_values),
|
||||||
|
debug,
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
// Use the original multi-line format for complex arrays
|
// Use the original multi-line format for complex arrays
|
||||||
println!("{}{}:", indent, style(key).dim());
|
println!("{}{}:", indent, style(key).dim());
|
||||||
@@ -609,8 +612,11 @@ fn print_params(value: &Value, depth: usize, debug: bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
print!("{}{}: ", indent, style(key).dim());
|
print_value_with_prefix(
|
||||||
print_value(val, debug);
|
&format!("{}{}: ", indent, style(key).dim()),
|
||||||
|
val,
|
||||||
|
debug,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -621,7 +627,7 @@ fn print_params(value: &Value, depth: usize, debug: bool) {
|
|||||||
print_params(item, depth + 1, debug);
|
print_params(item, depth + 1, debug);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => print_value(value, debug),
|
_ => print_value(value, debug, 0),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user