use bamboo_agent_core::tools::{ToolCall, ToolResult};
const PAUSE_TOOLS: [&str; 3] = [
"ExitPlanMode",
"conclusion_with_options",
"request_permissions",
];
#[derive(Debug, Clone)]
pub(super) struct UserQuestionPayload {
pub question: String,
pub options: Vec<String>,
pub allow_custom: bool,
}
pub(super) fn should_handle_user_question_tool(tool_call: &ToolCall, result: &ToolResult) -> bool {
let normalized = bamboo_tools::normalize_tool_ref(&tool_call.function.name)
.unwrap_or_else(|| tool_call.function.name.trim().to_string());
PAUSE_TOOLS.contains(&normalized.as_str()) && result.success
}
pub(super) fn parse_user_question_payload(result_content: &str) -> Option<UserQuestionPayload> {
let payload = serde_json::from_str::<serde_json::Value>(result_content).ok()?;
let question = payload["question"]
.as_str()
.unwrap_or("Please select:")
.to_string();
let options: Vec<String> = payload["options"]
.as_array()
.map(|arr| {
arr.iter()
.filter_map(|v| v.as_str().map(String::from))
.collect()
})
.unwrap_or_default();
let allow_custom = payload["allow_custom"].as_bool().unwrap_or(true);
Some(UserQuestionPayload {
question,
options,
allow_custom,
})
}