summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/config/mod.rs19
-rw-r--r--src/config/session.rs2
-rw-r--r--src/main.rs2
-rw-r--r--src/repl/mod.rs4
4 files changed, 14 insertions, 13 deletions
diff --git a/src/config/mod.rs b/src/config/mod.rs
index cd857b8..2bde0f7 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -93,6 +93,8 @@ pub struct Config {
pub model: Model,
#[serde(skip)]
pub last_message: Option<(Input, String)>,
+ #[serde(skip)]
+ pub in_repl: bool,
}
impl Default for Config {
@@ -122,6 +124,7 @@ impl Default for Config {
session: None,
model: Default::default(),
last_message: None,
+ in_repl: false,
}
}
}
@@ -595,8 +598,7 @@ impl Config {
format!("Failed to cleanup previous '{TEMP_SESSION_NAME}' session")
})?;
}
- let mut session = Session::new(self, TEMP_SESSION_NAME);
- session.set_save_session(None);
+ let session = Session::new(self, TEMP_SESSION_NAME);
self.session = Some(session);
}
Some(name) => {
@@ -605,9 +607,9 @@ impl Config {
self.session = Some(Session::new(self, name));
} else {
let session = Session::load(name, &session_path)?;
- let model = session.model().to_string();
+ let model_id = session.model().to_string();
self.session = Some(session);
- self.set_model(&model)?;
+ self.set_model(&model_id)?;
}
}
}
@@ -628,16 +630,13 @@ impl Config {
Ok(())
}
- /// End the current session, saving it if necessary
- /// The single argument `interactive` ensures that non-interactive sessions will never prompt
- pub fn end_session(&mut self, interactive: bool) -> Result<()> {
+ pub fn end_session(&mut self) -> Result<()> {
if let Some(mut session) = self.session.take() {
self.last_message = None;
let save_session = session.save_session();
if session.dirty && save_session != Some(false) {
- if save_session.is_none() {
- if !interactive {
- // If we're not interactive, we will not prompt and will not save
+ if save_session.is_none() || session.is_temp() {
+ if !self.in_repl {
return Ok(());
}
let ans = Confirm::new("Save session?").with_default(false).prompt()?;
diff --git a/src/config/session.rs b/src/config/session.rs
index 9af11aa..6ab855c 100644
--- a/src/config/session.rs
+++ b/src/config/session.rs
@@ -225,9 +225,9 @@ impl Session {
let model_id = model.id();
if self.model_id != model_id {
self.model_id = model_id;
- self.model = model;
self.dirty = true;
}
+ self.model = model;
Ok(())
}
diff --git a/src/main.rs b/src/main.rs
index dc64a34..203cc61 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -143,7 +143,7 @@ fn start_directive(
};
// Save the message/session
config.write().save_message(input, &output)?;
- config.write().end_session(false)?;
+ config.write().end_session()?;
Ok(())
}
diff --git a/src/repl/mod.rs b/src/repl/mod.rs
index 1633774..0a601c7 100644
--- a/src/repl/mod.rs
+++ b/src/repl/mod.rs
@@ -74,6 +74,8 @@ pub struct Repl {
impl Repl {
pub fn init(config: &GlobalConfig) -> Result<Self> {
+ config.write().in_repl = true;
+
let editor = Self::create_editor(config)?;
let prompt = ReplPrompt::new(config);
@@ -212,7 +214,7 @@ impl Repl {
self.config.write().clear_role()?;
}
Some("session") => {
- self.config.write().end_session(true)?;
+ self.config.write().end_session()?;
}
Some(_) => unknown_command()?,
None => {