summaryrefslogtreecommitdiffstats
path: root/src/config/mod.rs
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2025-01-18 09:12:08 +0800
committerGitHub <noreply@github.com>2025-01-18 09:12:08 +0800
commitcf3e9691373a776985222e3878b8418b7caf5dcf (patch)
treebd09ea288ecb1e2e8fb44b1a49d2646fd6a158f3 /src/config/mod.rs
parent58c3cdc9d9c65ff2ef89eaf16588e613d9ca2f49 (diff)
downloadaichat-cf3e9691373a776985222e3878b8418b7caf5dcf.tar.gz
refactor: improve `.agent` repl command (#1094)
Diffstat (limited to 'src/config/mod.rs')
-rw-r--r--src/config/mod.rs27
1 files changed, 20 insertions, 7 deletions
diff --git a/src/config/mod.rs b/src/config/mod.rs
index 20f19e5..19bd239 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -3,7 +3,7 @@ mod input;
mod role;
mod session;
-pub use self::agent::{list_agents, Agent, AgentVariables};
+pub use self::agent::{list_agents, Agent, AgentDefinition, AgentVariables};
pub use self::input::Input;
pub use self::role::{
Role, RoleLike, CODE_ROLE, CREATE_TITLE_ROLE, EXPLAIN_SHELL_ROLE, SHELL_ROLE,
@@ -1798,12 +1798,25 @@ impl Config {
};
values = candidates.into_iter().map(|v| (v, None)).collect();
filter = args[1];
- } else if cmd == ".agent" && args.len() == 2 {
- let dir = Self::agent_data_dir(args[0]).join(SESSIONS_DIR_NAME);
- values = list_file_names(dir, ".yaml")
- .into_iter()
- .map(|v| (v, None))
- .collect();
+ } else if cmd == ".agent" {
+ if args.len() == 2 {
+ let dir = Self::agent_data_dir(args[0]).join(SESSIONS_DIR_NAME);
+ values = list_file_names(dir, ".yaml")
+ .into_iter()
+ .map(|v| (v, None))
+ .collect();
+ }
+ let definition_file_path = Self::agent_functions_dir(args[0]).join("index.yaml");
+ if definition_file_path.exists() {
+ if let Ok(definition) = AgentDefinition::load(&definition_file_path) {
+ values.extend(
+ definition
+ .variables
+ .iter()
+ .map(|v| (format!("{}=", v.name), Some(v.description.clone()))),
+ );
+ }
+ }
};
values
.into_iter()