Add -with-remote-extension (#2062)
This commit is contained in:
@@ -14,6 +14,7 @@ pub async fn build_session(
|
||||
identifier: Option<Identifier>,
|
||||
resume: bool,
|
||||
extensions: Vec<String>,
|
||||
remote_extensions: Vec<String>,
|
||||
builtins: Vec<String>,
|
||||
debug: bool,
|
||||
) -> Session {
|
||||
@@ -126,6 +127,14 @@ pub async fn build_session(
|
||||
}
|
||||
}
|
||||
|
||||
// Add remote extensions if provided
|
||||
for extension_str in remote_extensions {
|
||||
if let Err(e) = session.add_remote_extension(extension_str).await {
|
||||
eprintln!("Failed to start extension: {}", e);
|
||||
process::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Add builtin extensions
|
||||
for builtin in builtins {
|
||||
if let Err(e) = session.add_builtin(builtin).await {
|
||||
|
||||
@@ -172,6 +172,37 @@ impl Session {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Add a remote extension to the session
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `extension_url` - URL of the server
|
||||
pub async fn add_remote_extension(&mut self, extension_url: String) -> Result<()> {
|
||||
let name: String = rand::thread_rng()
|
||||
.sample_iter(&Alphanumeric)
|
||||
.take(8)
|
||||
.map(char::from)
|
||||
.collect();
|
||||
|
||||
let config = ExtensionConfig::Sse {
|
||||
name,
|
||||
uri: extension_url,
|
||||
envs: Envs::new(HashMap::new()),
|
||||
description: Some(goose::config::DEFAULT_EXTENSION_DESCRIPTION.to_string()),
|
||||
// TODO: should set timeout
|
||||
timeout: Some(goose::config::DEFAULT_EXTENSION_TIMEOUT),
|
||||
};
|
||||
|
||||
self.agent
|
||||
.add_extension(config)
|
||||
.await
|
||||
.map_err(|e| anyhow::anyhow!("Failed to start extension: {}", e))?;
|
||||
|
||||
// Invalidate the completion cache when a new extension is added
|
||||
self.invalidate_completion_cache().await;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Add a builtin extension to the session
|
||||
///
|
||||
/// # Arguments
|
||||
|
||||
Reference in New Issue
Block a user