use std::collections::HashMap;
use serde::{Deserialize, Serialize};
use async_trait::async_trait;
use crate::error::Error;
use crate::workspace_context::WorkspaceContext;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DeepSeekConfig {
pub base_url: String,
pub api_key: String,
pub model: String,
pub max_tokens: u32,
pub temperature: f32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AgentConfig {
pub deepseek: DeepSeekConfig,
pub behavior: BehaviorConfig,
pub workspace: WorkspaceConfig,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BehaviorConfig {
pub max_retries: u32,
pub timeout_seconds: u64,
pub verbose_logging: bool,
pub tool_strategy: ToolStrategy,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ToolStrategy {
Auto,
Priority(Vec<String>),
Parallel,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WorkspaceConfig {
pub directories: Vec<String>,
pub smart_detection: bool,
pub exclude_patterns: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum AgentState {
Idle,
Thinking,
ExecutingTool(String),
WaitingForAPI,
Error(String),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AgentMessage {
pub id: String,
pub message_type: MessageType,
pub content: String,
pub timestamp: u64,
pub tool_calls: Vec<ToolCall>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum MessageType {
UserInput,
AgentResponse,
ToolCall,
ToolResult,
System,
Error,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ToolCall {
pub name: String,
pub arguments: HashMap<String, serde_json::Value>,
pub call_id: String,
pub status: ToolCallStatus,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ToolCallStatus {
Pending,
Executing,
Success,
Failed(String),
}
#[derive(Debug)]
pub struct AgentContext {
pub state: AgentState,
pub message_history: Vec<AgentMessage>,
pub workspace_context: Box<dyn WorkspaceContext + Send + Sync>,
pub available_tools: HashMap<String, ToolInfo>,
pub current_task: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ToolInfo {
pub name: String,
pub description: String,
pub input_schema: serde_json::Value,
pub server: String,
}
#[async_trait]
pub trait Agent: Send + Sync {
async fn initialize(&mut self) -> Result<(), Error>;
async fn process_input(&mut self, input: &str) -> Result<String, Error>;
async fn process_input_with_iterations(&mut self, input: &str, max_iterations: usize) -> Result<String, Error>;
async fn execute_tool(&mut self, tool_call: &ToolCall) -> Result<serde_json::Value, Error>;
fn get_state(&self) -> &AgentState;
fn get_context(&self) -> &AgentContext;
async fn reset(&mut self) -> Result<(), Error>;
}