use super::sql_format::{collapse_whitespace, format_sql};
pub(crate) fn tool_call_detail(name: &str, arguments: &serde_json::Value) -> Option<String> {
match name {
"bounded_sql_query" | "bounded_sql_query_all" => {
let sql = arguments.get("sql").and_then(serde_json::Value::as_str)?;
let sql = collapse_whitespace(sql);
if sql.is_empty() {
return None;
}
let connection = arguments
.get("connection")
.and_then(serde_json::Value::as_str)
.filter(|value| !value.is_empty());
Some(match (name, connection) {
(_, Some(connection)) => format!("{sql} (@{connection})"),
("bounded_sql_query_all", None) => format!("{sql} (all connected databases)"),
_ => sql,
})
}
_ => None,
}
}
pub(crate) struct SqlCall {
pub(crate) target: Option<String>,
pub(crate) sql: String,
}
pub(crate) fn sql_tool_call(name: &str, arguments: &serde_json::Value) -> Option<SqlCall> {
match name {
"bounded_sql_query" | "bounded_sql_query_all" => {
let raw = arguments.get("sql").and_then(serde_json::Value::as_str)?;
let sql = format_sql(raw);
if sql.is_empty() {
return None;
}
let connection = arguments
.get("connection")
.and_then(serde_json::Value::as_str)
.filter(|value| !value.is_empty());
let target = match (name, connection) {
(_, Some(connection)) => Some(format!("@{connection}")),
("bounded_sql_query_all", None) => Some("all connected databases".to_string()),
_ => None,
};
Some(SqlCall { target, sql })
}
_ => None,
}
}