use std::collections::HashMap;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Action {
pub id: Uuid,
pub action_type: String,
pub resource: String,
pub agent_id: String,
pub parameters: HashMap<String, serde_json::Value>,
pub timestamp: DateTime<Utc>,
}
impl Action {
pub fn new(
action_type: impl Into<String>,
resource: impl Into<String>,
agent_id: impl Into<String>,
) -> Self {
Self {
id: Uuid::new_v4(),
action_type: action_type.into(),
resource: resource.into(),
agent_id: agent_id.into(),
parameters: HashMap::new(),
timestamp: Utc::now(),
}
}
pub fn with_param(
mut self,
key: impl Into<String>,
value: impl Into<serde_json::Value>,
) -> Self {
self.parameters.insert(key.into(), value.into());
self
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_action_creation() {
let action = Action::new("tool_call", "bash", "agent-1");
assert_eq!(action.action_type, "tool_call");
assert_eq!(action.resource, "bash");
assert_eq!(action.agent_id, "agent-1");
assert!(action.parameters.is_empty());
}
#[test]
fn test_action_with_params() {
let action = Action::new("tool_call", "bash", "agent-1")
.with_param("command", serde_json::Value::String("ls -la".into()));
assert_eq!(action.parameters.len(), 1);
assert_eq!(
action.parameters.get("command").unwrap(),
&serde_json::Value::String("ls -la".into())
);
}
}