i forget
This commit is contained in:
parent
18864201d4
commit
1a8b4f1fff
15
src/cli.rs
15
src/cli.rs
|
|
@ -372,6 +372,21 @@ impl ChatCLI {
|
|||
}
|
||||
}
|
||||
}
|
||||
SessionAction::SetAsDefault(session_name) => {
|
||||
let mut config = crate::config::Config::load().unwrap_or_default();
|
||||
match config.set_default_session(session_name.clone()) {
|
||||
Ok(()) => {
|
||||
self.display.print_command_result(&format!(
|
||||
"Session '{}' is now the default session",
|
||||
session_name
|
||||
));
|
||||
}
|
||||
Err(e) => {
|
||||
self.display.print_error(&format!("Failed to set default session: {}", e));
|
||||
}
|
||||
}
|
||||
// Continue to show session list
|
||||
}
|
||||
SessionAction::Cancel => {
|
||||
return Ok(());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,10 @@ use std::env;
|
|||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
|
||||
fn default_session_name() -> String {
|
||||
"default".to_string()
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Config {
|
||||
pub api: ApiConfig,
|
||||
|
|
@ -27,6 +31,8 @@ pub struct DefaultsConfig {
|
|||
pub reasoning_effort: String,
|
||||
pub enable_web_search: bool,
|
||||
pub enable_reasoning_summary: bool,
|
||||
#[serde(default = "default_session_name")]
|
||||
pub default_session: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
|
|
@ -72,6 +78,7 @@ impl Default for DefaultsConfig {
|
|||
reasoning_effort: "medium".to_string(),
|
||||
enable_web_search: true,
|
||||
enable_reasoning_summary: false,
|
||||
default_session: "default".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -232,4 +239,9 @@ impl Config {
|
|||
println!(" Request timeout: {}s", self.api.request_timeout_seconds);
|
||||
println!(" Max conversation history: {}", self.limits.max_conversation_history);
|
||||
}
|
||||
|
||||
pub fn set_default_session(&mut self, session_name: String) -> Result<()> {
|
||||
self.defaults.default_session = session_name;
|
||||
self.save()
|
||||
}
|
||||
}
|
||||
13
src/main.rs
13
src/main.rs
|
|
@ -16,8 +16,8 @@ use crate::utils::Display;
|
|||
#[command(about = "A lightweight command-line interface for chatting with AI models")]
|
||||
#[command(version)]
|
||||
struct Args {
|
||||
#[arg(short, long, default_value = "default", help = "Session name")]
|
||||
session: String,
|
||||
#[arg(short, long, help = "Session name (defaults to configured default session)")]
|
||||
session: Option<String>,
|
||||
|
||||
#[arg(short, long, help = "Model name to use (overrides saved value)")]
|
||||
model: Option<String>,
|
||||
|
|
@ -44,7 +44,10 @@ async fn main() -> Result<()> {
|
|||
let env_vars = Config::validate_env_variables().context("Environment validation failed")?;
|
||||
|
||||
// Load or create session
|
||||
let session = match Session::load(&args.session) {
|
||||
// Use configured default session if none specified
|
||||
let session_name = args.session.unwrap_or_else(|| config.defaults.default_session.clone());
|
||||
|
||||
let session = match Session::load(&session_name) {
|
||||
Ok(mut session) => {
|
||||
if let Some(model) = args.model {
|
||||
if !is_model_supported(&model) {
|
||||
|
|
@ -69,9 +72,9 @@ async fn main() -> Result<()> {
|
|||
"Model '{}' is not supported. Falling back to '{}'",
|
||||
default_model, config.defaults.model
|
||||
));
|
||||
Session::new(args.session, config.defaults.model.clone())
|
||||
Session::new(session_name.clone(), config.defaults.model.clone())
|
||||
} else {
|
||||
Session::new(args.session, default_model)
|
||||
Session::new(session_name, default_model)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -184,7 +184,7 @@ impl InputHandler {
|
|||
|
||||
// If it's the current session, show options
|
||||
if Some(selected_session.to_string().as_str()) == current_session {
|
||||
let options = vec!["Delete this session", "Cancel"];
|
||||
let options = vec!["Delete this session", "Set as default session", "Cancel"];
|
||||
let action_result = match Select::with_theme(&theme)
|
||||
.with_prompt("This is your current session. What would you like to do?")
|
||||
.items(&options)
|
||||
|
|
@ -197,11 +197,14 @@ impl InputHandler {
|
|||
|
||||
match action_result {
|
||||
Some(0) => {
|
||||
if self.confirm(&format!("Delete current session '{}'? You will need to create or switch to another session after deletion.", selected_session.to_string()))? {
|
||||
if self.confirm(&format!("Delete current session '{}'? You will need to create or switch to another sessions after deletion.", selected_session.to_string()))? {
|
||||
return Ok(SessionAction::Delete(selected_session));
|
||||
}
|
||||
return Ok(SessionAction::Cancel);
|
||||
}
|
||||
Some(1) => {
|
||||
return Ok(SessionAction::SetAsDefault(selected_session));
|
||||
}
|
||||
_ => return Ok(SessionAction::Cancel),
|
||||
}
|
||||
} else {
|
||||
|
|
@ -209,6 +212,7 @@ impl InputHandler {
|
|||
let options = vec![
|
||||
format!("Switch to '{}'", selected_session.to_string()),
|
||||
format!("Delete '{}'", selected_session.to_string()),
|
||||
format!("Set '{}' as default session", selected_session.to_string()),
|
||||
"Cancel".to_string()
|
||||
];
|
||||
|
||||
|
|
@ -230,6 +234,7 @@ impl InputHandler {
|
|||
}
|
||||
return Ok(SessionAction::Cancel);
|
||||
}
|
||||
Some(2) => return Ok(SessionAction::SetAsDefault(selected_session)),
|
||||
_ => return Ok(SessionAction::Cancel),
|
||||
}
|
||||
}
|
||||
|
|
@ -243,6 +248,7 @@ impl InputHandler {
|
|||
pub enum SessionAction<T> {
|
||||
Switch(T),
|
||||
Delete(T),
|
||||
SetAsDefault(T),
|
||||
Cancel,
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue