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 }
|
Self { agent }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Run the REPL
|
/// Run the REPL (async version)
|
||||||
pub fn run(&self) -> Result<(), Box<dyn std::error::Error>> {
|
pub async fn run(&self) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
println!("svibe REPL - Type 'exit' or 'quit' to leave");
|
println!("svibe REPL - Type 'exit' or 'quit' to leave");
|
||||||
println!("Commands: /help, /clear, /status, /agents, /tools");
|
println!("Commands: /help, /clear, /status, /agents, /tools");
|
||||||
println!();
|
println!();
|
||||||
@@ -48,20 +48,8 @@ impl Repl {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process as a task - need to use tokio runtime
|
// Process as a task
|
||||||
let input = input.to_string();
|
let result = self.process_task(input).await;
|
||||||
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
|
|
||||||
});
|
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
@@ -81,6 +69,16 @@ impl Repl {
|
|||||||
Ok(())
|
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>> {
|
fn handle_command(&self, input: &str) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let parts: Vec<&str> = input.split_whitespace().collect();
|
let parts: Vec<&str> = input.split_whitespace().collect();
|
||||||
|
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
None | Some(Commands::Repl) => {
|
None | Some(Commands::Repl) => {
|
||||||
// Start REPL
|
// Start REPL
|
||||||
let repl = Repl::new(agent);
|
let repl = Repl::new(agent);
|
||||||
if let Err(e) = repl.run() {
|
if let Err(e) = repl.run().await {
|
||||||
eprintln!("REPL error: {}", e);
|
eprintln!("REPL error: {}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user