summaryrefslogtreecommitdiffstats
path: root/src/config/session.rs
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2024-08-30 20:00:07 +0800
committerGitHub <noreply@github.com>2024-08-30 20:00:07 +0800
commitd8d52b60d6dba47a0c318e68172e2d28e5351385 (patch)
treee67fd41faa1eaea83d8956754b3bffb1ea07d466 /src/config/session.rs
parent4bbf4796169e2840b59dc29cbc6fb36e7959d24d (diff)
downloadaichat-d8d52b60d6dba47a0c318e68172e2d28e5351385.tar.gz
feat: save temp session with `temp-<timestamp>` if `save_session: true` (#811)
Diffstat (limited to 'src/config/session.rs')
-rw-r--r--src/config/session.rs14
1 files changed, 7 insertions, 7 deletions
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)?;