mirror of
https://github.com/aaif-goose/goose.git
synced 2026-07-03 14:10:03 +02:00
fix: sanitize server names for passing into model tool calls (#563)
This commit is contained in:
@@ -19,6 +19,20 @@ pub struct Capabilities {
|
||||
provider_usage: Mutex<Vec<ProviderUsage>>,
|
||||
}
|
||||
|
||||
/// Sanitizes a string by replacing invalid characters with underscores.
|
||||
/// Valid characters match [a-zA-Z0-9_-]
|
||||
fn sanitize(input: String) -> String {
|
||||
let mut result = String::with_capacity(input.len());
|
||||
for c in input.chars() {
|
||||
result.push(if c.is_ascii_alphanumeric() || c == '_' || c == '-' {
|
||||
c
|
||||
} else {
|
||||
'_'
|
||||
});
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
impl Capabilities {
|
||||
/// Create a new Capabilities with the specified provider
|
||||
pub fn new(provider: Box<dyn Provider>) -> Self {
|
||||
@@ -64,7 +78,7 @@ impl Capabilities {
|
||||
|
||||
// Store the client
|
||||
self.clients.insert(
|
||||
init_result.server_info.name.clone(),
|
||||
sanitize(init_result.server_info.name.clone()),
|
||||
Arc::new(Mutex::new(client)),
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user