mirror of
https://github.com/aljazceru/goose.git
synced 2025-12-19 15:14:21 +01:00
feat: improve tool loading (#2193)
This commit is contained in:
@@ -2,6 +2,10 @@ use cliclack::spinner;
|
||||
use console::style;
|
||||
use goose::agents::extension::ToolInfo;
|
||||
use goose::agents::extension_manager::get_parameter_names;
|
||||
use goose::agents::platform_tools::{
|
||||
PLATFORM_ENABLE_EXTENSION_TOOL_NAME, PLATFORM_LIST_RESOURCES_TOOL_NAME,
|
||||
PLATFORM_READ_RESOURCE_TOOL_NAME,
|
||||
};
|
||||
use goose::agents::Agent;
|
||||
use goose::agents::{extension::Envs, ExtensionConfig};
|
||||
use goose::config::extensions::name_to_key;
|
||||
@@ -921,6 +925,24 @@ pub fn toggle_experiments_dialog() -> Result<(), Box<dyn Error>> {
|
||||
}
|
||||
|
||||
pub async fn configure_tool_permissions_dialog() -> Result<(), Box<dyn Error>> {
|
||||
let mut extensions: Vec<String> = ExtensionConfigManager::get_all()
|
||||
.unwrap_or_default()
|
||||
.into_iter()
|
||||
.filter(|ext| ext.enabled)
|
||||
.map(|ext| ext.config.name().clone())
|
||||
.collect();
|
||||
extensions.push("platform".to_string());
|
||||
|
||||
let selected_extension_name = cliclack::select("Choose an extension to configure tools")
|
||||
.items(
|
||||
&extensions
|
||||
.iter()
|
||||
.map(|ext| (ext.clone(), ext.clone(), ""))
|
||||
.collect::<Vec<_>>(),
|
||||
)
|
||||
.interact()?;
|
||||
|
||||
// Fetch tools for the selected extension
|
||||
// Load config and get provider/model
|
||||
let config = Config::global();
|
||||
|
||||
@@ -937,28 +959,36 @@ pub async fn configure_tool_permissions_dialog() -> Result<(), Box<dyn Error>> {
|
||||
|
||||
// Create the agent
|
||||
let mut agent = Agent::new(provider);
|
||||
for extension in ExtensionConfigManager::get_all().expect("should load extensions") {
|
||||
if extension.enabled {
|
||||
let config = extension.config.clone();
|
||||
agent
|
||||
.add_extension(config.clone())
|
||||
.await
|
||||
.unwrap_or_else(|_| {
|
||||
println!(
|
||||
"{} Failed to check extension: {}",
|
||||
style("Error").red().italic(),
|
||||
config.name()
|
||||
);
|
||||
});
|
||||
}
|
||||
if let Ok(Some(config)) = ExtensionConfigManager::get_config_by_name(&selected_extension_name) {
|
||||
agent
|
||||
.add_extension(config.clone())
|
||||
.await
|
||||
.unwrap_or_else(|_| {
|
||||
println!(
|
||||
"{} Failed to check extension: {}",
|
||||
style("Error").red().italic(),
|
||||
config.name()
|
||||
);
|
||||
});
|
||||
} else {
|
||||
println!(
|
||||
"{} Configuration not found for extension: {}",
|
||||
style("Warning").yellow().italic(),
|
||||
selected_extension_name
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let mut permission_manager = PermissionManager::default();
|
||||
// Fetch the list of tools grouped by extension
|
||||
let tools: Vec<ToolInfo> = agent
|
||||
.list_tools()
|
||||
let selected_tools = agent
|
||||
.list_tools(Some(selected_extension_name.clone()))
|
||||
.await
|
||||
.into_iter()
|
||||
.filter(|tool| {
|
||||
tool.name != PLATFORM_ENABLE_EXTENSION_TOOL_NAME
|
||||
&& tool.name != PLATFORM_LIST_RESOURCES_TOOL_NAME
|
||||
&& tool.name != PLATFORM_READ_RESOURCE_TOOL_NAME
|
||||
})
|
||||
.map(|tool| {
|
||||
ToolInfo::new(
|
||||
&tool.name,
|
||||
@@ -967,37 +997,21 @@ pub async fn configure_tool_permissions_dialog() -> Result<(), Box<dyn Error>> {
|
||||
permission_manager.get_user_permission(&tool.name),
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
|
||||
let mut tools_by_extension: HashMap<String, Vec<ToolInfo>> = HashMap::new();
|
||||
|
||||
for tool in tools {
|
||||
if let Some((extension_name, _tool_name)) = tool.name.split_once("__") {
|
||||
tools_by_extension
|
||||
.entry(extension_name.to_string())
|
||||
.or_default()
|
||||
.push(tool);
|
||||
}
|
||||
}
|
||||
|
||||
// Ask the user to choose an extension
|
||||
let extension_name = cliclack::select("Choose an extension to configure tools")
|
||||
.items(
|
||||
&tools_by_extension
|
||||
.keys()
|
||||
.map(|ext| (ext.clone(), ext.clone(), ""))
|
||||
.collect::<Vec<_>>(),
|
||||
)
|
||||
.interact()?;
|
||||
|
||||
// Fetch tools for the selected extension
|
||||
let selected_tools = tools_by_extension.get(&extension_name).unwrap();
|
||||
.collect::<Vec<ToolInfo>>();
|
||||
|
||||
let tool_name = cliclack::select("Choose a tool to update permission")
|
||||
.items(
|
||||
&selected_tools
|
||||
.iter()
|
||||
.map(|tool| (tool.name.clone(), tool.name.clone(), &tool.description))
|
||||
.map(|tool| {
|
||||
let first_description = tool
|
||||
.description
|
||||
.split('.')
|
||||
.next()
|
||||
.unwrap_or("No description available")
|
||||
.trim();
|
||||
(tool.name.clone(), tool.name.clone(), first_description)
|
||||
})
|
||||
.collect::<Vec<_>>(),
|
||||
)
|
||||
.interact()?;
|
||||
|
||||
Reference in New Issue
Block a user