diff options
| author | sigoden <sigoden@gmail.com> | 2024-08-30 20:00:07 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-30 20:00:07 +0800 |
| commit | d8d52b60d6dba47a0c318e68172e2d28e5351385 (patch) | |
| tree | e67fd41faa1eaea83d8956754b3bffb1ea07d466 /src/config | |
| parent | 4bbf4796169e2840b59dc29cbc6fb36e7959d24d (diff) | |
| download | aichat-d8d52b60d6dba47a0c318e68172e2d28e5351385.tar.gz | |
feat: save temp session with `temp-<timestamp>` if `save_session: true` (#811)
Diffstat (limited to 'src/config')
| -rw-r--r-- | src/config/agent.rs | 9 | ||||
| -rw-r--r-- | src/config/mod.rs | 3 | ||||
| -rw-r--r-- | src/config/session.rs | 14 |
3 files changed, 11 insertions, 15 deletions
diff --git a/src/config/agent.rs b/src/config/agent.rs index 25e128c..bf4ef54 100644 --- a/src/config/agent.rs +++ b/src/config/agent.rs @@ -420,14 +420,7 @@ fn builtin_variables() -> Vec<(&'static str, String)> { ("__arch__", env::consts::ARCH.to_string()), ("__shell__", SHELL.name.clone()), ("__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(), - ), + ("__now__", now()), ( "__cwd__", env::current_dir() diff --git a/src/config/mod.rs b/src/config/mod.rs index 72f6d5a..d293c44 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -991,6 +991,9 @@ impl Config { for entry in rd.flatten() { let name = entry.file_name(); if let Some(name) = name.to_string_lossy().strip_suffix(".yaml") { + if name.starts_with(TEMP_SESSION_NAME) { + continue; + } names.push(name.to_string()); } } diff --git a/src/config/session.rs b/src/config/session.rs index c36c9db..4051936 100644 --- a/src/config/session.rs +++ b/src/config/session.rs @@ -51,15 +51,10 @@ pub struct Session { impl Session { pub fn new(config: &Config, name: &str) -> Self { - let save_session = if name == TEMP_SESSION_NAME { - None - } else { - config.save_session - }; let role = config.extract_role(); let mut session = Self { name: name.to_string(), - save_session, + save_session: config.save_session, ..Default::default() }; session.set_role(role); @@ -188,8 +183,9 @@ impl Session { .map(|(name, value)| format!("{name:<20}{value}")) .collect(); + lines.push(String::new()); + if !self.is_empty() { - lines.push("".into()); let resolve_url_fn = |url: &str| resolve_data_url(&self.data_urls, url.to_string()); for message in &self.messages { @@ -313,6 +309,10 @@ impl Session { }) .prompt()?; } + } else if save_session == Some(true) && session_name == TEMP_SESSION_NAME { + let now = chrono::Local::now(); + let formatted_time = now.format("%Y%m%dT%H:%M:%S").to_string(); + session_name = format!("{TEMP_SESSION_NAME}-{formatted_time}"); } let session_path = session_dir.join(format!("{session_name}.yaml")); self.save(&session_name, &session_path, is_repl)?; |
