add HumanInterface

add cli
This commit is contained in:
milan
2026-04-11 15:33:27 +02:00
parent 5bf98a1efc
commit 5aaedbd73f
9 changed files with 156 additions and 29 deletions
+38
View File
@@ -0,0 +1,38 @@
use crate::human_interface::{HumanInterface, HumanInterfaceError};
use dialoguer::theme::ColorfulTheme;
use dialoguer::{Confirm, Input};
use own_mcp::mcp::chat::PermissionAnswer;
pub struct CommandLine;
impl HumanInterface for CommandLine {
fn agent_message(&self, message: String) {
println!("ai: {}", message);
}
async fn expect_user_message(&self) -> Result<String, HumanInterfaceError> {
let user_message: String = Input::with_theme(&ColorfulTheme::default())
.with_prompt("you")
.interact_text()
.map_err(|e| HumanInterfaceError::IoError(e.into()))?;
Ok(user_message)
}
async fn ask_for_permission(&self,
mcp_server_name: String,
tool_name: String,
) -> Result<PermissionAnswer, HumanInterfaceError> {
let confirmation = Confirm::with_theme(&ColorfulTheme::default())
.with_prompt(format!("Allow usage of {mcp_server_name}:{tool_name}"))
.interact()
.map_err(|e| HumanInterfaceError::IoError(e.into()))?;
match confirmation {
true => Ok(PermissionAnswer::Granted),
false => Ok(PermissionAnswer::Denied),
}
}
async fn run(&self) -> Result<(), HumanInterfaceError> {
Ok(())
}
}
+22
View File
@@ -0,0 +1,22 @@
pub mod cli;
use thiserror::Error;
use own_mcp::mcp::chat::PermissionAnswer;
#[derive(Debug, Error)]
pub enum HumanInterfaceError {
#[error(transparent)]
IoError(std::io::Error),
#[error("other error in human interface: {0}")]
Other(String)
}
pub trait HumanInterface {
fn agent_message(&self, message: String);
fn expect_user_message(&self) -> impl Future<Output = Result<String, HumanInterfaceError>>;
fn ask_for_permission(&self, mcp_server_name: String, tool_name:String) -> impl Future<Output = Result<PermissionAnswer, HumanInterfaceError>>;
fn run(&self) -> impl Future<Output = Result<(), HumanInterfaceError>>;
}