From 58c3cdc9d9c65ff2ef89eaf16588e613d9ca2f49 Mon Sep 17 00:00:00 2001 From: sigoden Date: Sat, 18 Jan 2025 08:46:33 +0800 Subject: feat: `.starter` accepts index other than text (#1093) --- src/repl/mod.rs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'src/repl') diff --git a/src/repl/mod.rs b/src/repl/mod.rs index 1d96885..ef7921d 100644 --- a/src/repl/mod.rs +++ b/src/repl/mod.rs @@ -13,7 +13,7 @@ use crate::config::{ }; use crate::render::render_error; use crate::utils::{ - abortable_run_with_spinner, create_abort_signal, set_text, temp_file, AbortSignal, + abortable_run_with_spinner, create_abort_signal, dimmed_text, set_text, temp_file, AbortSignal, }; use anyhow::{bail, Context, Result}; @@ -450,9 +450,25 @@ pub async fn run_repl_command( } }, ".starter" => match args { - Some(value) => { - let input = Input::from_str(config, value, None); - ask(config, abort_signal.clone(), input, true).await?; + Some(id) => { + let mut text = None; + if let Some(agent) = config.read().agent.as_ref() { + for (i, value) in agent.conversation_staters().iter().enumerate() { + if (i + 1).to_string() == id { + text = Some(value.clone()); + } + } + } + match text { + Some(text) => { + println!("{}", dimmed_text(&format!(">> {}", text))); + let input = Input::from_str(config, &text, None); + ask(config, abort_signal.clone(), input, true).await?; + } + None => { + bail!("Invalid starter value"); + } + } } None => { let banner = config.read().agent_banner()?; -- cgit v1.2.3