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
+5 -4
View File
@@ -7,9 +7,10 @@ use ollama_rs::Ollama;
use rmcp::model::{CallToolRequestParams, CallToolResult};
use rmcp::ServiceError;
use std::collections::HashMap;
use serde::Deserialize;
use thiserror::Error;
#[derive(Debug, Copy, Clone, Default, PartialEq)]
#[derive(Debug, Copy, Clone, Default, Deserialize, PartialEq)]
pub enum ToolPermission {
Allowed,
#[default]
@@ -186,7 +187,7 @@ impl AgentChat {
pub async fn message<C: Future<Output = PermissionAnswer>>(
&mut self,
user_message: String,
permission_request_callback: fn(mcp_server_name: String, tool_name: String) -> C,
mut permission_request_callback: impl FnMut(String, String) -> C,
) -> Result<ChatMessage, ChatError>
{
let all_tools: Vec<ToolInfo> = self
@@ -213,7 +214,7 @@ impl AgentChat {
for tool_call in &response.message.tool_calls {
log::debug!("calling tool {}", tool_call.function.name);
let result = self.call_tool(tool_call, permission_request_callback).await?;
let result = self.call_tool(tool_call, &mut permission_request_callback).await?;
let contents = match result {
Some(result) => result.content
@@ -256,7 +257,7 @@ impl AgentChat {
async fn call_tool<C: Future<Output = PermissionAnswer>>(
&self,
tool_call: &ollama_rs::generation::tools::ToolCall,
permission_request_callback: fn(mcp_server_name: String, tool_name: String) -> C,
permission_request_callback: &mut impl FnMut(String, String) -> C,
) -> Result<Option<CallToolResult>, ChatError> {
let arguments_json_object = tool_call
.function