Skip to main content

sprite/models/
mod.rs

1//! Data models for the Sprite multi-agent workflow toolkit.
2//!
3//! This module contains the core data structures that define agents, sessions,
4//! configurations, and other entities used throughout the application.
5
6pub mod agent;
7pub mod config;
8pub mod session;
9
10// Re-export commonly used types
11pub use agent::{Agent, AgentStatus};
12pub use config::{
13    LoggingConfig, PerformanceSettings, ProjectConfig, ProjectSettings, SecuritySettings,
14    SyncConfig,
15};
16
17use chrono::{DateTime, Utc};
18use serde::{Deserialize, Serialize};
19use std::collections::HashMap;
20
21/// Log levels for configuration.
22#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
23pub enum LogLevel {
24    Error,
25    Warn,
26    #[default]
27    Info,
28    Debug,
29    Trace,
30}
31
32/// Conflict resolution strategies.
33#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
34pub enum ConflictResolution {
35    #[default]
36    Manual,
37    AutoTheirs,
38    AutoOurs,
39}
40
41/// Command message for agent communication.
42#[derive(Debug, Clone, Serialize, Deserialize)]
43pub struct CommandMessage {
44    /// Unique message identifier
45    pub id: String,
46
47    /// Message timestamp
48    pub timestamp: DateTime<Utc>,
49
50    /// Target agent name (empty for broadcast)
51    pub target_agent: Option<String>,
52
53    /// Command to execute
54    pub command: String,
55
56    /// Command arguments
57    pub args: Vec<String>,
58
59    /// Working directory for command
60    pub work_dir: Option<String>,
61
62    /// Environment variables for this command
63    pub env_vars: HashMap<String, String>,
64
65    /// Timeout for this command
66    pub timeout_secs: Option<u64>,
67
68    /// Message priority
69    pub priority: MessagePriority,
70}
71
72/// Message priority levels.
73#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
74pub enum MessagePriority {
75    Low,
76    #[default]
77    Normal,
78    High,
79    Critical,
80}
81
82/// Execution result for commands.
83#[derive(Debug, Clone, Serialize, Deserialize)]
84pub struct ExecutionResult {
85    /// Corresponding command message ID
86    pub command_id: String,
87
88    /// Agent that executed the command
89    pub agent_name: String,
90
91    /// Execution status
92    pub status: ExecutionStatus,
93
94    /// Command output (stdout)
95    pub output: String,
96
97    /// Error output (stderr)
98    pub error_output: String,
99
100    /// Exit code
101    pub exit_code: i32,
102
103    /// Execution start time
104    pub start_time: DateTime<Utc>,
105
106    /// Execution end time
107    pub end_time: DateTime<Utc>,
108
109    /// Resource usage during execution
110    pub resource_usage: ResourceUsage,
111}
112
113/// Execution status.
114#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
115pub enum ExecutionStatus {
116    Success,
117    Failed,
118    Timeout,
119    Cancelled,
120}
121
122/// Resource usage metrics.
123#[derive(Debug, Clone, Serialize, Deserialize)]
124pub struct ResourceUsage {
125    /// CPU usage percentage
126    pub cpu_percent: f64,
127
128    /// Memory usage in MB
129    pub memory_mb: u64,
130
131    /// Disk usage in MB
132    pub disk_mb: u64,
133}
134
135impl Default for ResourceUsage {
136    fn default() -> Self {
137        Self {
138            cpu_percent: 0.0,
139            memory_mb: 0,
140            disk_mb: 0,
141        }
142    }
143}