fix: normalize extension names consistently in ExtensionManager (#6529)
Signed-off-by: rabi <ramishra@redhat.com>
This commit is contained in:
@@ -14,7 +14,7 @@ use super::platform_tools;
|
||||
use super::tool_execution::{ToolCallResult, CHAT_MODE_TOOL_SKIPPED_RESPONSE, DECLINED_RESPONSE};
|
||||
use crate::action_required_manager::ActionRequiredManager;
|
||||
use crate::agents::extension::{ExtensionConfig, ExtensionResult, ToolInfo};
|
||||
use crate::agents::extension_manager::{get_parameter_names, normalize, ExtensionManager};
|
||||
use crate::agents::extension_manager::{get_parameter_names, ExtensionManager};
|
||||
use crate::agents::extension_manager_extension::MANAGE_EXTENSIONS_TOOL_NAME_COMPLETE;
|
||||
use crate::agents::final_output_tool::{FINAL_OUTPUT_CONTINUATION_MESSAGE, FINAL_OUTPUT_TOOL_NAME};
|
||||
use crate::agents::platform_tools::PLATFORM_MANAGE_SCHEDULE_TOOL_NAME;
|
||||
@@ -690,11 +690,10 @@ impl Agent {
|
||||
|
||||
async move {
|
||||
let name = config_clone.name().to_string();
|
||||
let normalized_name = normalize(&name);
|
||||
|
||||
if agent_ref
|
||||
.extension_manager
|
||||
.is_extension_enabled(&normalized_name)
|
||||
.is_extension_enabled(&name)
|
||||
.await
|
||||
{
|
||||
tracing::debug!("Extension {} already loaded, skipping", name);
|
||||
|
||||
@@ -713,10 +713,11 @@ impl ExtensionManager {
|
||||
info: Option<ServerInfo>,
|
||||
temp_dir: Option<TempDir>,
|
||||
) {
|
||||
let normalized = normalize(&name);
|
||||
self.extensions
|
||||
.lock()
|
||||
.await
|
||||
.insert(name, Extension::new(config, client, info, temp_dir));
|
||||
.insert(normalized, Extension::new(config, client, info, temp_dir));
|
||||
self.invalidate_tools_cache_and_bump_version().await;
|
||||
}
|
||||
|
||||
@@ -761,7 +762,8 @@ impl ExtensionManager {
|
||||
}
|
||||
|
||||
pub async fn is_extension_enabled(&self, name: &str) -> bool {
|
||||
self.extensions.lock().await.contains_key(name)
|
||||
let normalized = normalize(name);
|
||||
self.extensions.lock().await.contains_key(&normalized)
|
||||
}
|
||||
|
||||
pub async fn get_extension_configs(&self) -> Vec<ExtensionConfig> {
|
||||
@@ -798,18 +800,21 @@ impl ExtensionManager {
|
||||
extension_name: Option<&str>,
|
||||
exclude: Option<&str>,
|
||||
) -> Vec<Tool> {
|
||||
let extension_name_normalized = extension_name.map(normalize);
|
||||
let exclude_normalized = exclude.map(normalize);
|
||||
|
||||
tools
|
||||
.iter()
|
||||
.filter(|tool| {
|
||||
let tool_prefix = tool.name.as_ref().split("__").next().unwrap_or("");
|
||||
|
||||
if let Some(excluded) = exclude {
|
||||
if let Some(ref excluded) = exclude_normalized {
|
||||
if tool_prefix == excluded {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(name_filter) = extension_name {
|
||||
if let Some(ref name_filter) = extension_name_normalized {
|
||||
tool_prefix == name_filter
|
||||
} else {
|
||||
true
|
||||
@@ -1439,10 +1444,11 @@ impl ExtensionManager {
|
||||
}
|
||||
|
||||
async fn get_server_client(&self, name: impl Into<String>) -> Option<McpClientBox> {
|
||||
let normalized = normalize(&name.into());
|
||||
self.extensions
|
||||
.lock()
|
||||
.await
|
||||
.get(&name.into())
|
||||
.get(&normalized)
|
||||
.map(|ext| ext.get_client())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user