mirror of
https://github.com/aljazceru/goose.git
synced 2026-01-06 07:54:23 +01:00
config: add optional extension description (#1743)
This commit is contained in:
@@ -504,15 +504,31 @@ pub fn configure_extensions_dialog() -> Result<(), Box<dyn Error>> {
|
||||
.placeholder(&goose::config::DEFAULT_EXTENSION_TIMEOUT.to_string())
|
||||
.validate(|input: &String| match input.parse::<u64>() {
|
||||
Ok(_) => Ok(()),
|
||||
Err(_) => Err("Please enter a valide timeout"),
|
||||
Err(_) => Err("Please enter a valid timeout"),
|
||||
})
|
||||
.interact()?;
|
||||
|
||||
// Split the command string into command and args
|
||||
// TODO: find a way to expose this to the frontend so we dont need to re-write code
|
||||
let mut parts = command_str.split_whitespace();
|
||||
let cmd = parts.next().unwrap_or("").to_string();
|
||||
let args: Vec<String> = parts.map(String::from).collect();
|
||||
|
||||
let add_desc = cliclack::confirm("Would you like to add a description?").interact()?;
|
||||
|
||||
let description = if add_desc {
|
||||
let desc = cliclack::input("Enter a description for this extension:")
|
||||
.placeholder("Description")
|
||||
.validate(|input: &String| match input.parse::<String>() {
|
||||
Ok(_) => Ok(()),
|
||||
Err(_) => Err("Please enter a valid description"),
|
||||
})
|
||||
.interact()?;
|
||||
Some(desc)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let add_env =
|
||||
cliclack::confirm("Would you like to add environment variables?").interact()?;
|
||||
|
||||
@@ -542,6 +558,7 @@ pub fn configure_extensions_dialog() -> Result<(), Box<dyn Error>> {
|
||||
cmd,
|
||||
args,
|
||||
envs: Envs::new(envs),
|
||||
description,
|
||||
timeout: Some(timeout),
|
||||
},
|
||||
})?;
|
||||
@@ -580,10 +597,25 @@ pub fn configure_extensions_dialog() -> Result<(), Box<dyn Error>> {
|
||||
.placeholder(&goose::config::DEFAULT_EXTENSION_TIMEOUT.to_string())
|
||||
.validate(|input: &String| match input.parse::<u64>() {
|
||||
Ok(_) => Ok(()),
|
||||
Err(_) => Err("Please enter a valide timeout"),
|
||||
Err(_) => Err("Please enter a valid timeout"),
|
||||
})
|
||||
.interact()?;
|
||||
|
||||
let add_desc = cliclack::confirm("Would you like to add a description?").interact()?;
|
||||
|
||||
let description = if add_desc {
|
||||
let desc = cliclack::input("Enter a description for this extension:")
|
||||
.placeholder("Description")
|
||||
.validate(|input: &String| match input.parse::<String>() {
|
||||
Ok(_) => Ok(()),
|
||||
Err(_) => Err("Please enter a valid description"),
|
||||
})
|
||||
.interact()?;
|
||||
Some(desc)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let add_env =
|
||||
cliclack::confirm("Would you like to add environment variables?").interact()?;
|
||||
|
||||
@@ -612,6 +644,7 @@ pub fn configure_extensions_dialog() -> Result<(), Box<dyn Error>> {
|
||||
name: name.clone(),
|
||||
uri,
|
||||
envs: Envs::new(envs),
|
||||
description,
|
||||
timeout: Some(timeout),
|
||||
},
|
||||
})?;
|
||||
|
||||
@@ -109,6 +109,7 @@ impl Session {
|
||||
cmd,
|
||||
args: parts.iter().map(|s| s.to_string()).collect(),
|
||||
envs: Envs::new(envs),
|
||||
description: Some(goose::config::DEFAULT_EXTENSION_DESCRIPTION.to_string()),
|
||||
// TODO: should set timeout
|
||||
timeout: Some(goose::config::DEFAULT_EXTENSION_TIMEOUT),
|
||||
};
|
||||
|
||||
@@ -115,6 +115,7 @@ async fn add_extension(
|
||||
name,
|
||||
uri,
|
||||
envs: Envs::new(env_map),
|
||||
description: None,
|
||||
timeout,
|
||||
}
|
||||
}
|
||||
@@ -151,6 +152,7 @@ async fn add_extension(
|
||||
name,
|
||||
cmd,
|
||||
args,
|
||||
description: None,
|
||||
envs: Envs::new(env_map),
|
||||
timeout,
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use dotenv::dotenv;
|
||||
use futures::StreamExt;
|
||||
use goose::agents::{AgentFactory, ExtensionConfig};
|
||||
use goose::config::DEFAULT_EXTENSION_TIMEOUT;
|
||||
use goose::config::{DEFAULT_EXTENSION_DESCRIPTION, DEFAULT_EXTENSION_TIMEOUT};
|
||||
use goose::message::Message;
|
||||
use goose::providers::databricks::DatabricksProvider;
|
||||
|
||||
@@ -18,6 +18,7 @@ async fn main() {
|
||||
let config = ExtensionConfig::stdio(
|
||||
"developer",
|
||||
"./target/debug/developer",
|
||||
DEFAULT_EXTENSION_DESCRIPTION,
|
||||
DEFAULT_EXTENSION_TIMEOUT,
|
||||
);
|
||||
agent.add_extension(config).await.unwrap();
|
||||
|
||||
@@ -56,6 +56,7 @@ pub enum ExtensionConfig {
|
||||
uri: String,
|
||||
#[serde(default)]
|
||||
envs: Envs,
|
||||
description: Option<String>,
|
||||
// NOTE: set timeout to be optional for compatibility.
|
||||
// However, new configurations should include this field.
|
||||
timeout: Option<u64>,
|
||||
@@ -70,6 +71,7 @@ pub enum ExtensionConfig {
|
||||
#[serde(default)]
|
||||
envs: Envs,
|
||||
timeout: Option<u64>,
|
||||
description: Option<String>,
|
||||
},
|
||||
/// Built-in extension that is part of the goose binary
|
||||
#[serde(rename = "builtin")]
|
||||
@@ -90,21 +92,28 @@ impl Default for ExtensionConfig {
|
||||
}
|
||||
|
||||
impl ExtensionConfig {
|
||||
pub fn sse<S: Into<String>, T: Into<u64>>(name: S, uri: S, timeout: T) -> Self {
|
||||
pub fn sse<S: Into<String>, T: Into<u64>>(name: S, uri: S, description: S, timeout: T) -> Self {
|
||||
Self::Sse {
|
||||
name: name.into(),
|
||||
uri: uri.into(),
|
||||
envs: Envs::default(),
|
||||
description: Some(description.into()),
|
||||
timeout: Some(timeout.into()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn stdio<S: Into<String>, T: Into<u64>>(name: S, cmd: S, timeout: T) -> Self {
|
||||
pub fn stdio<S: Into<String>, T: Into<u64>>(
|
||||
name: S,
|
||||
cmd: S,
|
||||
description: S,
|
||||
timeout: T,
|
||||
) -> Self {
|
||||
Self::Stdio {
|
||||
name: name.into(),
|
||||
cmd: cmd.into(),
|
||||
args: vec![],
|
||||
envs: Envs::default(),
|
||||
description: Some(description.into()),
|
||||
timeout: Some(timeout.into()),
|
||||
}
|
||||
}
|
||||
@@ -120,12 +129,14 @@ impl ExtensionConfig {
|
||||
cmd,
|
||||
envs,
|
||||
timeout,
|
||||
description,
|
||||
..
|
||||
} => Self::Stdio {
|
||||
name,
|
||||
cmd,
|
||||
envs,
|
||||
args: args.into_iter().map(Into::into).collect(),
|
||||
description,
|
||||
timeout,
|
||||
},
|
||||
other => other,
|
||||
|
||||
@@ -7,6 +7,7 @@ use utoipa::ToSchema;
|
||||
|
||||
pub const DEFAULT_EXTENSION: &str = "developer";
|
||||
pub const DEFAULT_EXTENSION_TIMEOUT: u64 = 300;
|
||||
pub const DEFAULT_EXTENSION_DESCRIPTION: &str = "";
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Clone, ToSchema)]
|
||||
pub struct ExtensionEntry {
|
||||
|
||||
@@ -8,4 +8,5 @@ pub use experiments::ExperimentManager;
|
||||
pub use extensions::{ExtensionEntry, ExtensionManager};
|
||||
|
||||
pub use extensions::DEFAULT_EXTENSION;
|
||||
pub use extensions::DEFAULT_EXTENSION_DESCRIPTION;
|
||||
pub use extensions::DEFAULT_EXTENSION_TIMEOUT;
|
||||
|
||||
Reference in New Issue
Block a user