Fix REPL panic: make run() async
The REPL was using block_on() inside an already running tokio runtime, which caused a panic. Changed run() to be async and await directly. Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
@@ -12,8 +12,8 @@ impl Repl {
|
||||
Self { agent }
|
||||
}
|
||||
|
||||
/// Run the REPL
|
||||
pub fn run(&self) -> Result<(), Box<dyn std::error::Error>> {
|
||||
/// Run the REPL (async version)
|
||||
pub async fn run(&self) -> Result<(), Box<dyn std::error::Error>> {
|
||||
println!("svibe REPL - Type 'exit' or 'quit' to leave");
|
||||
println!("Commands: /help, /clear, /status, /agents, /tools");
|
||||
println!();
|
||||
@@ -48,20 +48,8 @@ impl Repl {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Process as a task - need to use tokio runtime
|
||||
let input = input.to_string();
|
||||
let agent = self.agent.clone();
|
||||
|
||||
let rt = tokio::runtime::Handle::current();
|
||||
let result = rt.block_on(async move {
|
||||
let request = AgentRequest {
|
||||
task: input,
|
||||
task_type: TaskType::Default,
|
||||
context: vec![],
|
||||
history: vec![],
|
||||
};
|
||||
agent.process(request).await
|
||||
});
|
||||
// Process as a task
|
||||
let result = self.process_task(input).await;
|
||||
|
||||
match result {
|
||||
Ok(response) => {
|
||||
@@ -81,6 +69,16 @@ impl Repl {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn process_task(&self, input: &str) -> Result<crate::agents::AgentResponse, crate::agents::AgentError> {
|
||||
let request = AgentRequest {
|
||||
task: input.to_string(),
|
||||
task_type: TaskType::Default,
|
||||
context: vec![],
|
||||
history: vec![],
|
||||
};
|
||||
self.agent.process(request).await
|
||||
}
|
||||
|
||||
fn handle_command(&self, input: &str) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let parts: Vec<&str> = input.split_whitespace().collect();
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ async fn main() -> anyhow::Result<()> {
|
||||
None | Some(Commands::Repl) => {
|
||||
// Start REPL
|
||||
let repl = Repl::new(agent);
|
||||
if let Err(e) = repl.run() {
|
||||
if let Err(e) = repl.run().await {
|
||||
eprintln!("REPL error: {}", e);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user