use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use chrono::{DateTime, Utc};
use tokio_util::sync::CancellationToken;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct McpServerConfig {
pub command: Option<String>,
pub args: Option<Vec<String>>,
pub env: Option<HashMap<String, String>>,
pub cwd: Option<String>,
pub url: Option<String>,
pub http_url: Option<String>,
pub headers: Option<HashMap<String, String>>,
pub timeout: Option<u64>,
pub trust: Option<bool>,
pub include_tools: Option<Vec<String>>,
pub exclude_tools: Option<Vec<String>>,
pub oauth: Option<OAuthConfig>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OAuthConfig {
pub enabled: bool,
pub authorization_url: Option<String>,
pub token_url: Option<String>,
pub scopes: Option<Vec<String>>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct McpConfig {
pub mcp_servers: HashMap<String, McpServerConfig>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ToolResult {
pub success: bool,
pub data: Option<serde_json::Value>,
pub error: Option<String>,
}
pub struct AgentContext {
pub available_tools: HashMap<String, Box<dyn Tool + Send + Sync>>,
pub conversation_history: Vec<ConversationMessage>,
pub current_working_directory: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ConversationMessage {
pub role: MessageRole,
pub content: String,
pub timestamp: DateTime<Utc>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum MessageRole {
User,
Assistant,
}
#[derive(Debug, Clone)]
pub struct AgentResponse {
pub message: String,
pub actions: Vec<AgentAction>,
pub content: Option<String>,
pub memory_updates: Option<serde_json::Value>,
}
#[derive(Debug, Clone)]
pub struct AgentAction {
pub tool: String,
pub params: HashMap<String, serde_json::Value>,
pub result: Option<ToolResult>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum ToolConfirmationOutcome {
Approved,
Rejected,
Unknown,
ProceedAlwaysServer,
ProceedAlwaysTool,
}
#[derive(Debug, Clone, PartialEq)]
pub enum Kind {
Other,
}
#[derive(Debug, Clone)]
pub struct ToolCallConfirmationDetails {
pub tool_name: String,
pub params: HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone)]
pub struct ToolMcpConfirmationDetails {
pub tool_type: String,
pub title: String,
pub server_name: String,
pub tool_name: String,
pub tool_display_name: String,
}
#[derive(Debug, Clone)]
pub struct ToolResultContent {
pub content: String,
pub mime_type: Option<String>,
pub llm_content: Option<serde_json::Value>,
pub return_display: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FunctionCall {
pub name: String,
pub args: HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone)]
pub struct DeepseekResponse {
pub content: String,
pub tool_calls: Option<Vec<ToolCall>>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ToolCall {
pub id: String,
pub call_type: ToolCallType,
pub function: Option<FunctionCallInfo>,
pub custom: Option<CustomCallInfo>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub enum ToolCallType {
Function,
Custom,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FunctionCallInfo {
pub name: String,
pub arguments: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CustomCallInfo {
pub name: String,
pub input: String,
}
#[derive(Debug, Clone)]
pub struct ToolExecutionResult {
pub tool_call_id: String,
pub name: String,
pub content: String,
pub success: bool,
pub error: Option<String>,
}
#[derive(Debug, Clone)]
pub struct DeepseekClientConfig {
pub api_key: String,
pub base_url: Option<String>,
pub timeout: Option<u64>,
pub max_retries: Option<u32>,
pub debug_mode: Option<bool>,
pub target_dir: Option<String>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum McpServerStatus {
Disconnected,
Connecting,
Connected,
}
#[derive(Debug, Clone, PartialEq)]
pub enum McpDiscoveryState {
NotStarted,
InProgress,
Completed,
}
#[derive(Debug, Clone, PartialEq)]
pub enum AuthProviderType {
GoogleCredentials,
None,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Part {
pub text: Option<String>,
pub inline_data: Option<InlineData>,
pub function_response: Option<FunctionResponse>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct InlineData {
pub mime_type: String,
pub data: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FunctionResponse {
pub name: String,
pub response: serde_json::Value,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type")]
pub enum McpContentBlock {
Text { text: String },
Image { mime_type: String, data: String },
Audio { mime_type: String, data: String },
Resource { resource: ResourceData },
ResourceLink { uri: String, title: Option<String>, name: Option<String> },
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ResourceData {
pub text: Option<String>,
pub blob: Option<String>,
pub mime_type: Option<String>,
}
#[async_trait::async_trait]
pub trait CallableTool {
async fn call_tool(&self, function_calls: Vec<FunctionCall>) -> Result<Vec<Part>, Box<dyn std::error::Error + Send + Sync>>;
}
#[async_trait::async_trait]
pub trait Tool {
fn name(&self) -> &str;
fn description(&self) -> &str;
fn display_name(&self) -> &str;
fn kind(&self) -> Kind;
fn parameter_schema(&self) -> &serde_json::Value;
fn is_output_markdown(&self) -> bool;
fn can_update_output(&self) -> bool;
fn as_any(&self) -> &dyn std::any::Any;
async fn should_confirm_execute(&self, _abort_signal: &CancellationToken) -> Result<Option<ToolCallConfirmationDetails>, Box<dyn std::error::Error + Send + Sync>> {
Ok(None)
}
async fn execute(&self, params: HashMap<String, serde_json::Value>) -> Result<ToolResultContent, Box<dyn std::error::Error + Send + Sync>>;
async fn build_and_execute(&self, params: HashMap<String, serde_json::Value>, _abort_signal: Option<&CancellationToken>) -> Result<ToolResultContent, Box<dyn std::error::Error + Send + Sync>> {
self.execute(params).await
}
}
#[async_trait::async_trait]
pub trait ToolInvocation {
fn name(&self) -> &str;
fn params(&self) -> &HashMap<String, serde_json::Value>;
async fn should_confirm_execute(&self, abort_signal: &CancellationToken) -> Result<Option<ToolCallConfirmationDetails>, Box<dyn std::error::Error + Send + Sync>>;
async fn execute(&self) -> Result<ToolResultContent, Box<dyn std::error::Error + Send + Sync>>;
fn get_description(&self) -> &str;
}