diff options
| author | sigoden <sigoden@gmail.com> | 2024-07-29 17:12:30 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-29 17:12:30 +0800 |
| commit | 14bfd4e97d0ea7d633e54595e17a54eb66529232 (patch) | |
| tree | e05eb7dfff5adf846f330413d6788140cb23da9a /src | |
| parent | 77df84923482dfcf70b2da1a24355bca9b2a2352 (diff) | |
| download | aichat-14bfd4e97d0ea7d633e54595e17a54eb66529232.tar.gz | |
feat: add builtin variables for agent (#762)
Diffstat (limited to 'src')
| -rw-r--r-- | src/config/agent.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/config/agent.rs b/src/config/agent.rs index c09c8a9..2b319ed 100644 --- a/src/config/agent.rs +++ b/src/config/agent.rs @@ -279,6 +279,9 @@ impl AgentDefinition { for variable in &self.variables { output = output.replace(&format!("{{{{{}}}}}", variable.name), &variable.value) } + for (key, value) in builtin_variables() { + output = output.replace(&format!("{{{{{}}}}}", key), &value); + } output } @@ -395,3 +398,27 @@ fn save_variables(variables_path: &Path, variables: &[AgentVariable]) -> Result< .with_context(|| format!("Failed to save variables to '{}'", variables_path.display()))?; Ok(()) } + +fn builtin_variables() -> Vec<(&'static str, String)> { + vec![ + ("__os__", env::consts::OS.to_string()), + ("__os_family__", env::consts::FAMILY.to_string()), + ("__arch__", env::consts::ARCH.to_string()), + ("__shell__", detect_shell().name), + ("__locale__", sys_locale::get_locale().unwrap_or_default()), + ( + "__now__", + time::OffsetDateTime::now_utc() + .format(simplelog::format_description!( + "[year]-[month]-[day]T[hour]:[minute]:[second].[subsecond digits:3]Z" + )) + .unwrap_or_default(), + ), + ( + "__cwd__", + env::current_dir() + .map(|v| v.display().to_string()) + .unwrap_or_default(), + ), + ] +} |
